如何将现有的Django项目迁移到新的空数据库(或架构)? [英] How to migrate an existing Django project to a new and empty database (or schema)?

查看:75
本文介绍了如何将现有的Django项目迁移到新的空数据库(或架构)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我从事Django(1.7.6版)项目的工作已有数月之久.在整个这段时间里,每个应用程序都发展了很多,现在有数十种迁移.

I have been working on a Django (version 1.7.6) project for various months. Throughout this time each application evolved a good deal and there now various dozens of migrations.

我想将此项目部署到新的开发环境中.我建立了一个具有空架构的数据库,并相应地更新了 settings.py .现在,我想从迁移中重新创建数据库结构,但是当我运行 python manage.py migrate

I would like to deploy this project into a new development environment. I set up a database with an empty schema and updated settings.py accordingly. Now I would like to recreate the database structure from the migrations, however I get the following exception when I run python manage.py migrate:

文件"/usr/lib/python2.7/dist-packages/django/db/backends/utils.py",第65行,在执行中返回self.cursor.execute(sql,params)django.db.utils.ProgrammingError:表"modules_server_proj_locations"不存在

File "/usr/lib/python2.7/dist-packages/django/db/backends/utils.py", line 65, in execute return self.cursor.execute(sql, params) django.db.utils.ProgrammingError: table "modules_server_proj_locations" does not exist

modules_server_proj_locations 是指不再存在的多对多关系,但由于某些原因,迁移仍在尝试使用它.

modules_server_proj_locations refers to a many-to-many relationship that no longer exists, but for some reason the migrations are still trying use it.

然后我尝试使用-fake 选项进行迁移,但这只会导致另一个异常:

I then tried to migrate with the --fake option, but this only results in a different exception:

文件"/usr/lib/python2.7/dist-packages/django/contrib/contenttypes/models.py",第58行,在get_for_model中在尝试分别迁移应用程序之前已迁移."RuntimeError:创建新的内容类型时出错.请确定在尝试分别迁移应用程序之前,先迁移contenttypes.

File "/usr/lib/python2.7/dist-packages/django/contrib/contenttypes/models.py", line 58, in get_for_model " is migrated before trying to migrate apps individually." RuntimeError: Error creating new content types. Please make sure contenttypes is migrated before trying to migrate apps individually.

我应该如何进行?

推荐答案

如果这是您的第一个版本,则可以删除整个数据库,删除所有迁移文件,然后运行 python manage.py makemigrations 以获得干净的数据库和迁移主题.否则,可能必须编辑迁移文件并从所有表中删除表跟踪.

If this is your first release then you can drop the whole database, remove all the migration files and then run python manage.py makemigrations for a clean database and migration theme. Otherwise, probably you have to edit migration files and remove the table trace from all.

这篇关于如何将现有的Django项目迁移到新的空数据库(或架构)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆