南迁移失败

时间:2012-01-20 13:57:30

标签: python django django-south

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

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]中断了:

# 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',

1 个答案:

答案 0 :(得分:2)

您不应该直接与您的模特互动。您使用django.models,但该版本的模型处于错误状态。您希望模型的状态与迁移0002中的状态一样。 south manual表示您应该通过orm参数访问模型。

  

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

所以你应该像这样重写迁移:

orders = orm.Order.objects.all()

或者甚至喜欢这样:

Order = orm.Order