2
我正在添加一个运行模式迁移的新模型。然后用数据迁移向该表添加数据。我在Postgres数据库上运行这个。我已经在本地成功运行SQLite数据库,所以我猜这是一个数据库特定的问题。在将datamigration出现的错误是:Django South Postgres数据迁移问题
Error in migration: app:0109_add_reservation_rates
DatabaseError: column "rate_currency" specified more than once
LINE 1: ...rate_currency", "rate", "reservation_id", "date", "rate_curr...
^
有没有更好的错误,南南合作给我,我还没有找到一种方法来产生南是应该运行的SQL。我检查了schemamigration,datamigration并没有重复字段名...
下面是实际的迁移: 0108_etc ... PY
# -*- coding: 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):
# Adding model 'ReservationRate'
db.create_table(u'app_reservationrate', (
(u'id', self.gf('django.db.models.fields.AutoField')(primary_key=True)),
('created_on', self.gf('django.db.models.fields.DateTimeField')(auto_now_add=True, blank=True)),
('updated_on', self.gf('django.db.models.fields.DateTimeField')(auto_now=True, blank=True)),
('reservation', self.gf('django.db.models.fields.related.ForeignKey')(related_name='reservation_rates', to=orm['app.Reservation'])),
('room', self.gf('django.db.models.fields.related.ForeignKey')(related_name='reservation_rates', to=orm['app.Room'])),
('date', self.gf('django.db.models.fields.DateField')(db_index=True)),
('rate_currency', self.gf('djmoney.models.fields.CurrencyField')(default='USD')),
('rate', self.gf('djmoney.models.fields.MoneyField')(max_digits=10, decimal_places=2, default_currency='USD')),
))
db.send_create_signal(u'app', ['ReservationRate'])
# Adding unique constraint on 'ReservationRate', fields ['reservation', 'room', 'date']
db.create_unique(u'app_reservationrate', ['reservation_id', 'room_id', 'date'])
0109_etc ... PY
coding: utf-8 -*-
import datetime
from south.db import db
from south.v2 import DataMigration
from django.db import models
class Migration(DataMigration):
def forwards(self, orm):
for reservation in orm.Reservation.objects.all():
# Loop through some code, get rates, and dates for creating ReservationRate objects...
orm.ReservationRate.objects.create(reservation=reservation, room=stay.room, date=date, rate=rate)
有人有线索如何解决这个问题?
它不是数据库特定的。它明确指出'rate_currency'出现两次 – karthikr
这不是。现在将实际的迁移片段添加到问题中。 – tzenderman