Django South Postgres Datamigration Issue

时间:2013-07-01 17:49:01

标签: django postgresql django-south

我正在添加一个新模型,运行模式迁移。然后使用数据迁移向该表添加数据。我在Postgres数据库上运行它。我在本地的SQLite数据库上成功运行它,所以我猜这是一个特定于数据库的问题。数据迁移中出现的错误是:

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,数据迁移,并且没有重复的字段名称......

以下是实际的迁移: 0108_etc ...吡啶

# -*- 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)

有人知道如何解决这个问题吗?

1 个答案:

答案 0 :(得分:2)

不完全确定原因,但运行./manage.py migrate -v2 app使一切正常。我相信该选项应该运行迁移并输出更多关于它正在运行的信息。