psycopg2.errors.UndefinedTable:关系 "authentication_author" 不存在:Django v4
psycopg2.errors.UndefinedTable: relation "authentication_author" does not exist: Django v4
我尝试在我的 Django 项目中开始使用 Postgresql 而不是 sqlite。
我在我的 Windows 上安装了 postgreqL,创建了一个新的数据库、用户和密码。
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql_psycopg2',
'NAME': 'database_name',
'USER': 'admin',
'PASSWORD': 'admin',
'HOST': 'localhost',
'PORT': '5432',
}
}
但是当我尝试迁移或进行迁移时,我得到了这个:
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...
这是我的模型:
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)
是的,我删除了 sqlite3 数据库、所有迁移文件夹,并在其中创建了新的 init.py。
还是遇到同样的问题
已更新
回溯截图:
它发生在 Django 上。有时您可以在尝试 makemigrations
.
时调用一些依赖于新数据库模式的代码
在这种情况下,您只需要暂时注释掉连接 makemigrations
与新模型架构的所有代码。就像在这个问题中一样,您可以使用完整的回溯来跟踪相关的代码块。
我尝试在我的 Django 项目中开始使用 Postgresql 而不是 sqlite。 我在我的 Windows 上安装了 postgreqL,创建了一个新的数据库、用户和密码。
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql_psycopg2',
'NAME': 'database_name',
'USER': 'admin',
'PASSWORD': 'admin',
'HOST': 'localhost',
'PORT': '5432',
}
}
但是当我尝试迁移或进行迁移时,我得到了这个:
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...
这是我的模型:
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)
是的,我删除了 sqlite3 数据库、所有迁移文件夹,并在其中创建了新的 init.py。
还是遇到同样的问题
已更新
回溯截图:
它发生在 Django 上。有时您可以在尝试 makemigrations
.
在这种情况下,您只需要暂时注释掉连接 makemigrations
与新模型架构的所有代码。就像在这个问题中一样,您可以使用完整的回溯来跟踪相关的代码块。