我嘗試在我的 Django 專案中開始使用 Postgresql 而不是 sqlite。我在我的 Windows 上安裝了 postgreqL,創建了一個新的資料庫、用戶和密碼。
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql_psycopg2',
'NAME': 'database_name',
'USER': 'admin',
'PASSWORD': 'admin',
'HOST': 'localhost',
'PORT': '5432',
}
}
但是當我嘗試遷移或 makemigrations 時,我得到了這個:
檔案“C:\Users\s...\venv\lib\site-packages\django\db\backends\utils.py”,第 85 行,在 _execute 中回傳 self.cursor.execute(sql, params) psycopg2.errors .UndefinedTable:關系“authentication_author”不存在第 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檔案夾。
但仍然遇到同樣的問題。
更新
回溯截圖:


uj5u.com熱心網友回復:
它發生在 Django 上。有時,您可以在嘗試呼叫時呼叫一些依賴于新資料庫架構的代碼makemigrations。
在這種情況下,您只需要暫時注釋掉makemigrations與新模型模式相關的所有代碼。就像在這個問題中一樣,您可以僅使用完整的回溯來跟蹤相關的代碼塊。
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/394738.html
