I tried to start using Postgresql instead of sqlite in my Django project. I installed postgreqL ON MY Windows, creatred a new database, user and password.
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql_psycopg2',
'NAME': 'database_name',
'USER': 'admin',
'PASSWORD': 'admin',
'HOST': 'localhost',
'PORT': '5432',
}
}
But when I try to migrate or makemigrations, I got this:
File "C:\Users\s...\venv\lib\site-packages\django\db\backends\utils.py", line 85, in _execute return self.cursor.execute(sql, params) psycopg2.errors.UndefinedTable: relation "authentication_author" does not exist LINE 1: ...hentication_author"."is_doctor" FROM "authentic...
here is my model:
class Author(models.Model):
user = models.OneToOneField(User, on_delete=models.CASCADE, null=True, related_name="author")
slug = models.CharField(max_length=50, null=True, blank=True,)
is_doctor = models.BooleanField(default=False)
And yes, I deleted the sqlite3 database, all the migrations folders and I created new ones with the init.py inside of them.
But still get the same problem.
Updated Traceback screenshots:
CodePudding user response:
It happens with Django. Sometimes you can invoke some code that relies on a new DB schema at the time you're trying to makemigrations
.
All you need in this situation is to temporarily comment out all the code that connects makemigrations
with your new model's schema. As it was in this question, you can trace related blocks of code just using full traceback.