首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >南迁失败

南迁失败
EN

Stack Overflow用户
提问于 2012-01-20 21:57:30
回答 1查看 512关注 0票数 0

我对南迁有个问题。我仍然不明白这是怎么发生的,以及应该采取什么途径来解决这个问题

代码语言:javascript
复制
Romans-MacBook-Pro:holms$ ./manage.py migrate 
cRunning migrations for accounts:
- Nothing to migrate.
 - Loading initial data for accounts.
No fixtures found.
Running migrations for allocations:
- Nothing to migrate.
 - Loading initial data for allocations.
No fixtures found.
Running migrations for adyen:
- Nothing to migrate.
 - Loading initial data for adyen.
No fixtures found.
Running migrations for blog:
- Nothing to migrate.
 - Loading initial data for blog.
No fixtures found.
Running migrations for offers:
- Nothing to migrate.
 - Loading initial data for offers.
No fixtures found.
Running migrations for orders:
 - Migrating forwards to 0011_update_price_fields.
 > orders:0002_update_order_contact_information
Traceback (most recent call last):
  File "./manage.py", line 15, in <module>
    execute_manager(settings)
  File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/core/management/__init__.py", line 438, in execute_manager
    utility.execute()
  File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/core/management/__init__.py", line 379, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/core/management/base.py", line 191, in run_from_argv
    self.execute(*args, **options.__dict__)
  File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/core/management/base.py", line 220, in execute
    output = self.handle(*args, **options)
  File "/Users/holms/Development/xxx/xxx/settings/../../lib/south/management/commands/migrate.py", line 105, in handle
    ignore_ghosts = ignore_ghosts,
  File "/Users/holms/Development/xxx/xxx/settings/../../lib/south/migration/__init__.py", line 191, in migrate_app
    success = migrator.migrate_many(target, workplan, database)
  File "/Users/holms/Development/xxx/xxx/settings/../../lib/south/migration/migrators.py", line 221, in migrate_many
    result = migrator.__class__.migrate_many(migrator, target, migrations, database)
  File "/Users/holms/Development/xxx/xxx/settings/../../lib/south/migration/migrators.py", line 292, in migrate_many
    result = self.migrate(migration, database)
  File "/Users/holms/Development/xxx/xxx/settings/../../lib/south/migration/migrators.py", line 125, in migrate
    result = self.run(migration)
  File "/Users/holms/Development/xxx/xxx/settings/../../lib/south/migration/migrators.py", line 99, in run
    return self.run_migration(migration)
  File "/Users/holms/Development/xxx/xxx/settings/../../lib/south/migration/migrators.py", line 81, in run_migration
    migration_function()
  File "/Users/holms/Development/xxx/xxx/settings/../../lib/south/migration/migrators.py", line 57, in <lambda>
    return (lambda: direction(orm))
  File "/Users/holms/Development/xxx/migrations/0002_update_order_contact_information.py", line 29, in forwards
    for o in orders:
  File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/db/models/query.py", line 107, in _result_iter
    self._fill_cache()
  File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/db/models/query.py", line 772, in _fill_cache
    self._result_cache.append(self._iter.next())
  File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/db/models/query.py", line 273, in iterator
    for row in compiler.results_iter():
  File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/db/models/sql/compiler.py", line 680, in results_iter
    for rows in self.execute_sql(MULTI):
  File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/db/models/sql/compiler.py", line 735, in execute_sql
    cursor.execute(sql, params)
  File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/db/backends/util.py", line 34, in execute
    return self.cursor.execute(sql, params)
  File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/db/backends/sqlite3/base.py", line 234, in execute
    return Database.Cursor.execute(self, query, params)
django.db.utils.DatabaseError: no such column: orders_order.pre_paid

迁移文件0002_update_order_contact_information.py的一部分中断:

代码语言:javascript
复制
# encoding: 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):
        Order = models.get_model('orders', 'Order')

        orders = Order.all_objects.select_related('buyer')
        orders = orders.filter(first_name__isnull=True)
        orders = orders.filter(buyer__isnull=False)
        orders = orders.exclude(payment_status="UNFINISHED")

        userfields = (
            'gender', 'birth_date', 'first_name', 'last_name', 'street_number',
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2012-01-20 22:20:16

你不应该像那样直接与你的模型交互。您使用django.models,但该版本的模型处于错误状态。您想要的是模型在迁移0002中的状态。south manual声明您应该通过orm参数访问模型。

请注意,我们使用orm.User访问用户模型-这为我们提供了创建此迁移时的用户版本,因此,如果我们希望在将来运行迁移,它将不会获得完全不同的新用户模型。source

因此,您应该像这样重写迁移:

代码语言:javascript
复制
orders = orm.Order.objects.all()

或者甚至像这样:

代码语言:javascript
复制
Order = orm.Order
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/8942483

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档