我想从django项目中删除一个应用程序。
我想移除
运行manage.py migrate app_to_remove zero
不起作用:
django.db.migrations.migration.IrreversibleError:
Operation <RunPython <function forwards_func at 0x7ff76075d668>> in
fooapp.0007_add_bar is not reversible
我想有几次迁徙是不可逆的.
发布于 2016-03-02 02:57:06
首先:删除代码中的引用
app_to_remove
中删除settings.INSTALLED_APPS
urls.py
或其他地方的其他引用第二:清理数据库
为django-项目创建一个空迁移:
manage.py makemigrations your_django_project --empty
编辑文件。下面是一个模板:
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('your_django_project', '0001_initial'),
]
operations = [
migrations.RunSQL('''
drop table if exists app_to_remove_table1;
drop table if exists app_to_remove_table2;
....
delete from auth_permission where content_type_id in (select id from django_content_type where app_label = '{app_label}');
delete from django_admin_log where content_type_id in (select id from django_content_type where app_label = '{app_label}');
delete from django_content_type where app_label = '{app_label}';
delete from django_migrations where app='{app_label}';
'''.format(app_label='app_to_remove'))
]
运行迁移,运行测试。
关于“如果存在”的话:有两种情况:
发布于 2020-10-07 04:15:52
注意:本指南成功地使用Django 3.1.1和Python3.8.2
您能尝试一下这个解决方案来先清理数据库和迁移吗?
步骤1:从_app/ itself s.py文件中删除表,但保留文件本身
步骤2:如果有,请检查文件admin.py中的寄存器
步骤3:创建迁移:
manage.py makemigrations your_app
步骤4:迁移到数据库:
manage.py migrate
您可以在我的示例中看到结果。
步骤5:删除您的应用程序/迁移文件夹中的所有文件
步骤6:删除表django_migrations中的迁移
python manage.py migrate --fake your_app zero
检查迁移情况:
python manage.py显示迁移
步骤7:然后您可以完全删除应用程序,检查引用,INSTALLED_APPS
https://stackoverflow.com/questions/35745220
复制相似问题