2012-01-20 3 views
0

사우스 마이 그 레이션에 문제가 있습니다. 난 아직도 이런 일이 않았다 방법을 이해하지 않으며, 나누기 마이그레이션 파일 [0002_update_order_contact_information.py]이사우스 마이 그 레이션에 실패했습니다.

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 

부분을 해결하기 위해 어떤 경로를 어떻게 이동해야합니다

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

답변

2

당신은 안 직접 모델과 상호 작용할 수 있습니다. django.models을 사용하지만 해당 버전의 모델이 잘못된 상태입니다. 마이그레이션 상태에서 모델의 상태를 원한다면 0002. south manual에는 orm 매개 변수를 통해 모델에 액세스해야한다고 나와 있습니다.

우리는 사용자 모델에 액세스하는 데 orm.User를 사용합니다. 이는 마이그레이션이 생성 된 시점의 사용자 버전을 제공하므로, 향후 마이그레이션을 실행하려면 완전히 다른, 새로운, 사용자 모델. source

그래서 당신은 다음과 같이 마이그레이션을 다시 작성해야합니다 같은

orders = orm.Order.objects.all() 

심지어을 :

Order = orm.Order 
난 그냥 마이그레이션 디렉토리를 삭제
+0

, 모든 것이 잘 갔다. 그러나 설명을 위해 thnx =) 누군가는 그것을 필요로 할 것입니다 – holms

관련 문제