我正在尝试将一些模型从一个 Django 应用程序迁移到另一个,并基于这个问题如何将模型从一个 django 应用程序迁移到一个新应用程序?我已经完成了很多工作,但是在创建第一个迁移时,我收到了这个错误:
"The model 'contenttype' from the app 'contenttypes' is not available in this migration."
谷歌和 SO 似乎没有找到任何发生这种情况的案例,并且上述问题也没有具体说明,除了代码中的注释:
if not db.dry_run:
# For permissions to work properly after migrating
orm['contenttypes.contenttype'].objects.filter(app_label='common', model='cat').update(app_label='specific')
非常感谢任何洞察我做错了什么。
这是两个迁移文件:
创造:
# encoding: utf-8
import datetime
from south.db import db
from south.v2 import SchemaMigration
from django.db import models
class Migration(SchemaMigration):
def forwards(self, orm):
db.rename_table('cars_country', 'general_country')
if not db.dry_run:
# For permissions to work properly after migrating
orm['contenttypes.ContentType'].objects.filter(app_label='cars', model='country').update(app_label='general')
def backwards(self, orm):
pass
删除:
# encoding: utf-8
import datetime
from south.db import db
from south.v2 import SchemaMigration
from django.db import models
class Migration(SchemaMigration):
depends_on = (
('general', '0002_create_country'),
)
def forwards(self, orm):
db.alter_column('cars_club', 'country_id', self.gf('django.db.models.fields.related.ForeignKey')(to=orm['general.Country'], null=True))
def backwards(self, orm):
db.rename_table('general_country', 'cars_country')
db.alter_column('cars_club', 'country_id', self.gf('django.db.models.fields.related.ForeignKey')(to=orm['cars.Country'], null=True))