mysql 데이터베이스에 약 500k 개 항목이있는 장고 모델이 있습니다. 내 모델에 다른 필드를 추가하고 싶습니다 :django-south schemamigration으로 데이터 손실
site = models.ForeignKey(Site, verbose_name=_('Site'),null=True,blank=True).
하지만 실행하여 모든 데이터가 손실 :
이python manage.py schemamigration product --auto
python manage.py migrate product
생성 된 이주 스크립트는 다음과 같습니다
class Migration(SchemaMigration):
def forwards(self, orm):
# Adding field 'Product.site'
db.add_column('product_product', 'site',
self.gf('django.db.models.fields.related.ForeignKey')(to=orm['sites.Site'], null=True, blank=True),
keep_default=False)
def backwards(self, orm):
# Deleting field 'Product.site'
db.delete_column('product_product', 'site_id')
마이그레이션을 위해 생성 된 SQL은 다음과 같습니다.
Running migrations for product:
- Migrating forwards to 0016_auto__add_field_product_site.
> product:0016_auto__add_field_product_site
= SET FOREIGN_KEY_CHECKS=0; []
= ALTER TABLE `product_product` ADD COLUMN `site_id` integer NULL; []
- no dry run output for alter_column() due to dynamic DDL, sorry
= ALTER TABLE `product_product` ADD CONSTRAINT `site_id_refs_id_10570b8a766fecf5` FOREIGN KEY (`site_id`) REFERENCES `django_site` (`id`); []
= CREATE INDEX `product_product_6223029` ON `product_product` (`site_id`); []
Th 'python manager.py migrate product - list'의 최신 마이그레이션 내역은 다음과 같습니다.
(*) 0011_auto__add_field_product_category_str
(*) 0012_auto__add_field_product_store_id
(*) 0013_auto__del_field_product_site__del_unique_product_sku_site__del_unique_
(*) 0014_auto__chg_field_product_short_description__chg_field_product_descripti
(*) 0015_auto__add_field_product_phase_tag
() 0016_auto__add_field_product_site
다행히 데이터베이스 백업이 있습니다. 기존 데이터를 잃지 않고 모델에 필드를 추가하는 방법이 있습니까?
'--auto' 옵션 대신 수동으로 마이그레이션을 시도해 보셨습니까? –
생성 된 마이그레이션 및 해당 실행 된 SQL의 내용을 표시하는 것이 더 좋을 수 있습니다. – okm
./manage.py migrate --list –