gue*_*tli 8 python django database-migration django-apps
我想从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
Run Code Online (Sandbox Code Playgroud)
我想有几次迁移是不可逆的......
gue*_*tli 13
app_to_remove从中移除settings.INSTALLED_APPSurls.py其他地方的其他引用为您的django项目创建一个空迁移:
manage.py makemigrations your_django_project --empty
Run Code Online (Sandbox Code Playgroud)
编辑文件.这是一个模板:
# -*- 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 if exists table app_to_remove_table1;
drop if exists table 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 reversion_version 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'))
]
Run Code Online (Sandbox Code Playgroud)
运行迁移,运行测试.
关于"drop if exists":你有两种情况:
| 归档时间: |
|
| 查看次数: |
6991 次 |
| 最近记录: |