gpt4 book ai didi

Django South Postgres 数据迁移问题

转载 作者:行者123 更新时间:2023-11-29 12:13:35 25 4
gpt4 key购买 nike

我正在添加一个新模型,运行一个架构迁移。然后使用数据迁移将数据添加到该表。我在 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)

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

最佳答案

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

关于Django South Postgres 数据迁移问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17410561/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com