I have 2 apps "app1", "app2" in my django project.
When I ran python3 manage.pymakemigrations
, I can see
...
Migrations for 'app1':
...
Migrations for 'app2':
...
But when I ran python3 manage.py migrate
, I got error saying
django.db.utils.ProgrammingError: relation "auth_user" does not exist
"auth_user" is db table for app1.User model, also is what AUTH_USER_MODEL refers to.
I tried to run migrate separately. It is fine for app2. But when I run python3 manage.py migrate
app1, I got
No migrations to apply.
Your models have changes that are not yet reflected in a migration, and so won't be applied.
Run 'manage.py makemigrations' to make new migrations, and then re-run 'manage.py migrate' to apply them.
I cannot find a solution for my case, anyone can help?
The user model code:
class User(AbstractBaseUser, Base):
USER_TYPE_CHOICES = ( (1, 'supervisor'), (2, 'admin'), (4, 'support'), ) email = models.EmailField(primary_key=True, max_length=256) name = models.CharField(max_length=45, null=True) password = models.CharField(max_length=256, null=True) last_login = models.DateTimeField(auto_now=True) active = models.BooleanField(default=True) user_type = models.PositiveSmallIntegerField( choices=USER_TYPE_CHOICES, default=2 ) USERNAME_FIELD = 'email' objects = UserManager() class Meta: db_table = 'auth_user' app_label = 'admin_portal' def __str__(self): return str(self.email) @property def is_admin(self): return self.user_type == 1 @property def is_active(self): return self.active
CodePudding user response:
Use this command separately for each app:
python3 manage.py makemigrations app1
python3 manage.py makemigrations app2
CodePudding user response:
Its bad idea but try this. Delete all migration, cache files nd do run makemigrations to each app not entirely.then run the migrate