gpt4 book ai didi

python - psycopg2.errors.UndefinedTable : relation "authentication_author" does not exist: Django v4

转载 作者:行者123 更新时间:2023-12-05 05:50:41 24 4
gpt4 key购买 nike

我尝试在我的 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 _executereturn self.cursor.execute(sql, params) psycopg2.errors.UndefinedTable: relation "authentication_author" doesnot 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 的新文件夹。

还是遇到同样的问题。

已更新回溯截图: second-error

first error

最佳答案

它发生在 Django 上。有时,您可以在尝试 makemigrations 时调用一些依赖于新数据库架构的代码。

在这种情况下,您只需要暂时注释掉所有连接 makemigrations 与新模型架构的代码。就像在这个问题中一样,您可以使用完整的回溯来跟踪相关的代码块。

关于python - psycopg2.errors.UndefinedTable : relation "authentication_author" does not exist: Django v4,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/70490552/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com