【问题标题】:Recreating a database for an existing django schema为现有的 django 模式重新创建数据库
【发布时间】:2016-08-17 22:06:06
【问题描述】:

我不小心删除了我的 Postgres 数据库。然后按照this solution我删除了迁移文件,但现在无法执行第三步的命令“python manage.py migrate --fake”。

RuntimeError: Error creating new content types. 
Please make sure contenttypes is migrated before trying to migrate apps individually.


psycopg2.ProgrammingError: relation "django_content_type" does not exist
LINE 1: ..."."app_label", "django_content_type"."model" FROM "django_co...
                                                         ^

我尝试运行“python manage.py migrate contenttypes”和“python manage.py makemigrations contenttypes --empty”,但都不起作用。

使用 django 1.9.5

【问题讨论】:

标签: django postgresql


【解决方案1】:

首先同步您的项目: 像这样:

python manage.py syncdb

完成后你可以运行:python manage.py makemigrations 和最后一个python manage.py migrate

【讨论】:

  • python manage.py syncdb 返回“未知命令:'syncdb'”。我尝试做python manage.py migrate --run-syncdb,但返回的结果与“迁移”完全相同
  • 你有哪些 django 版本?
  • 我使用的是 Django 1.9.5
  • 如果你有 django 1.9 使用 makemigrations 像这样: python manage.py makemigrations;在 1.9 中删除了 syncdb,您必须使用 makemigrations 和 migrate (python manage.py migrate)。不要忘记在 makemigrations 命令中添加 s。
  • 是的,我已经完成了标准的 makemigrations,然后进行了迁移。在 makemigrations 之后,我得到“没有检测到任何更改”,并且在迁移之后,我得到了 contenttypes 错误,就像我原来的帖子中一样
猜你喜欢
  • 2019-12-24
  • 2011-01-15
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-10-27
  • 1970-01-01
  • 1970-01-01
  • 2011-01-09
相关资源
最近更新 更多