У меня есть абстрактная модель, которую я конвертирую в конкретную модель. Я успешно использую юг для изменения схемы, но не могу использовать миграцию данных.
Мое начальное состояние:
class UserProfile(models.Model):
user = models.OneToOneField(User, primary_key=True, \
related_name='profile')
class Meta:
abstract=True
class SpecificProfile(UserProfile):
url = models.URLField()
Мое новое состояние:
class UserProfile(models.Model):
user = models.OneToOneField(User, primary_key=True, \
related_name='profile')
class SpecificProfile(UserProfile):
user_profile = models.OneToOneField(UserProfile, parent_link=True)
url = models.URLField()
Моя миграция схемы:
class Migration(SchemaMigration):
def forwards(self, orm):
# Renaming field 'SpecProfile.user_profile'
db.rename_column('specificprofile', 'user_id', 'user_profile_id')
# Adding model 'UserProfile'
db.create_table('userprofile', (
('user', self.gf('django.db.models.fields.related.OneToOneField')(related_name='profile', unique=True, primary_key=True, to=orm['auth.User'])),
))
db.send_create_signal('myapp', ['UserProfile'])
Я отредактировал файл, созданный на юге, чтобы переименовать одно поле в SpecificProfile
Теперь, в процессе переноса данных, я хотел бы создать одну запись UserProfile для SpecificProfile
и назначить UserProfile.user_id
для SpecificProfile.user_profile_id
.
Итак, мои перенаправления данных:
class Migration(DataMigration):
def forwards(self, orm):
for spec in orm.SpecificProfile.objects.all():
user_profile = orm.UserProfile()
user_profile.user_id = spec.user_profile_id
user_profile.save()
Сценарий выполняется без ошибок, но не создает никакой новой записи в таблице UserProfile.
Должен ли я использовать UserProfile()
вместо orm.UserProfile()
?
Есть идеи?