2

我正在添加一个新模型,运行模式迁移。然后通过数据迁移将数据添加到该表。我在 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...
                                                             ^

South 没有给我更好的错误,而且我还没有找到一种方法来生成 South 应该运行的 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)

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

4

1 回答 1

2

不完全确定为什么,但运行./manage.py migrate -v2 app使一切正常。我相信该选项应该运行迁移并输出有关其运行内容的更多信息。

于 2013-07-01T23:28:30.603 回答