Search code examples
pythondjangodjango-modelsdjango-registration

Django model foreign key from existing table


In my django project I use django-registration reusable app. I install this app and run syncdb. It's create for me table 'registration_registrationprofiles' in my database. Then I create a new app and write this code in my models.py:

class Comments(models.Model):
    text = models.TextField()
    pub_date = models.DateTimeField(auto_now=True)
    user = models.ForeignKey('registration_registrationprofiles')

And run manage.py makemigrations and it throw me exception:

ERRORS:
comments.Comments.user: (fields.E300) Field defines a relation 
with model 'registration_registrationprofiles', which is either
not installed, or is abstract.

How I can fix this problem?


Solution

  • Try this:

    from registration.models import RegistrationProfile
    

    and then:

    user = models.ForeignKey(RegistrationProfile)