简体   繁体   English

Django 1.7迁移问题与我的旧项目有关

[英]Django 1.7 Migrations issue with my old project

I have a django 1.5 app , now I migrated it to django 1.7 and app is working fine with old database. 我有一个django 1.5应用程序,现在我将它迁移到django 1.7并且应用程序与旧数据库正常工作。 But Now I want create migrations for that app using django 1.7. 但现在我想使用django 1.7为该应用程序创建迁移。

I deleted old migrations and just kept migrations folders with __ init__ files 我删除了旧的迁移,只是使用__ init__文件保留了迁移文件夹

then I ran ./manage.py makemigrations 然后我跑了./manage.py makemigrations

while running ./manage.py migrate its giving some errors. 在运行./manage.py migrate它会给出一些错误。

django.db.utils.ProgrammingError: relation "django_site" does not exist
LINE 1: SELECT (1) AS "a" FROM "django_site" LIMIT 1

I have added django_sites to installed apps. 我已将django_sites添加到已安装的应用中。

Is there any particular way to create/apply migrations when updating to native migrations? 在更新到本机迁移时,是否有任何特定的方法来创建/应用迁移?

you have a migration that depend on django.contrib.site but is the tables related are not available. 您有一个依赖于django.contrib.site的迁移,但是相关的表不可用。 you can 您可以

  • move django.contrib.site up in the INSTALLED_APPS 将django.contrib.site移到INSTALLED_APPS中
  • check the attribute dependencies of your migration 检查迁移的属性dependencies

Anyway I think your problem is with the default value of some field. 无论如何,我认为你的问题是一些字段的默认值。

If you don't find the involved application you can: 如果您没有找到涉及的应用程序,您可以:

  1. disable all the apps in the INSTALLED_APPS 禁用INSTALLED_APPS中的所有应用
  2. enable the first one 启用第一个
  3. run makemigrations 运行makemigrations
  4. delete all migrations 删除所有迁移
  5. enable the next application 启用下一个应用程序
  6. run makemigrations ... repeat step 4..6 until you get the error 运行makemigrations ...重复步骤4..6,直到出现错误

From the documentation : 文档

If you already have pre-existing migrations created with South, then the upgrade process to use django.db.migrations is quite simple: 如果您已经使用South创建了预先存在的迁移,那么使用django.db.migrations的升级过程非常简单:

  • Ensure all installs are fully up-to-date with their migrations. 确保所有安装都完全与其迁移保持同步。
  • Remove 'south' from INSTALLED_APPS. 从INSTALLED_APPS中删除“south”。
  • Delete all your (numbered) migration files, but not the directory or init .py - make sure you remove the .pyc files too. 删除所有(编号)迁移文件,但不删除目录或init .py - 确保也删除.pyc文件。
  • Run python manage.py makemigrations. 运行python manage.py makemigrations。 Django should see the empty migration directories and make new initial migrations in the new format. Django应该看到空的迁移目录并以新格式进行新的初始迁移。 Run python manage.py migrate. 运行python manage.py migrate。 Django will see that the tables for the initial migrations already exist and mark them as applied without running them. Django将看到初始迁移的表已经存在,并将它们标记为已应用而不运行它们。

I suspect you forgot to 我怀疑你忘记了

find . -iname "*.pyc" | xargs rm

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM