我有以前的django项目和django项目。我从旧django的数据库中创建了转储文件。我还修改了表并创建了新的表。
现在,我想将转储文件加载到我的新django应用程序中。当我首先迁移,然后恢复数据,或者首先恢复然后迁移时,我会遇到错误。当我首先进行迁移时,它说表已经存在了。
当我首先恢复时,它说django.db.utils.ProgrammingError: relation "django_content_type" already exists
我使用migrate --fake
error goes,但是新表不是在数据库中创建的。
我花了3-4天,但没能成功。
如果可以的话请帮帮我。
PS:我的数据库是postgresql
发布于 2021-06-15 07:00:48
这不是直截了当的,需要一些人工干预,这取决于你将来想做什么。
managed = False
设置为模型的元,这将使Django跳过对这些模型的进行迁移
更加复杂。
1. Delete all your migrations
2. You need to make your models equivalent to your database, you can set `managed=False` for new models like `Users`
3. Run `python manage.py makemigrations`, this will create the structure of the initial database.
4. Fake running the migrations `python manage.py migrate --fake`
5. Dump the records of django\_migrations table
6. Create a new empty migration (with --empty) and add the SQL statements of the `django_migrations` table to it using `migrations.RunSQL()`
7. now fake again so you skip that new migration.
8. Now you are ready to use migrations as usual.
安装新数据库时,只需运行python manage.py migrate
即可。
https://stackoverflow.com/questions/67980803
复制相似问题