Home > Blockchain >  Profile table not being created for extended User model in django
Profile table not being created for extended User model in django

Time:10-07

I am facing this problem in django where even though there is a Profile model in my models.py file which extends the django User model still on running the 'makemigration' and 'migrate' commands the Profile table is not being generated in database.

This is my models.py:

class Profile(models.Model):
    user = models.OneToOneField(User, on_delete=models.CASCADE)
    clg_name = models.CharField(max_length=200)


class Student(models.Model):
    name = models.CharField(max_length=100, blank=False)
    enrollment_number = models.IntegerField(unique=True, null=True, blank=False)
    clg_name = models.CharField(max_length=200, blank=False)
    program_name = models.CharField(max_length=30, blank=False)

class Result(models.Model):
    student = models.ForeignKey(Student, on_delete=models.CASCADE)
    sem = models.IntegerField()
    exam_name = models.CharField(max_length=30)
    percnt = models.FloatField(null=True)
    cgpa = models.FloatField(null=True)

class Marks(models.Model):
    result = models.ForeignKey(Result, on_delete=models.CASCADE)
    course_name = models.CharField(max_length=100, null=True)
    course_code = models.IntegerField(null=True)
    course_credit = models.IntegerField(null=True)    
    grade = models.FloatField(null=True)

Here is the output of py manage.py makemigration account:

Migrations for 'account':
  account\migrations\0001_initial.py
    - Create model Result
    - Create model Profile
    - Create model Marks

And this is the output of py manage.py migrate:

Operations to perform:
  Apply all migrations: account, admin, auth, contenttypes, sessions
Running migrations:
  No migrations to apply.

CodePudding user response:

I don't know what is wrong with your account app . but you can solve it with :

1- delete __pycache__ and migrations folders located inside account app

2 - run python manage.py makemigrations account zero

3 - then run python manage.py makemigrations account

4 - finally run python manage.py migrate

CodePudding user response:

I solved the following error by just dropping the whole Database and deleting the py_cache and migration files of my application. Just create another database and rerun the migration and migrate commands. Hope this helps.

  • Related