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