南迁移后没有这样的专栏

时间:2013-05-06 02:39:35

标签: python django migration django-south

我在此问题中遇到了与用户相同的问题,但遗憾的是answer没有解决任何问题。关于我遵循指定方向时发生的事情的一些评论:

当我尝试--delete-ghost-migrations命令时出现错误

The app 'tixeng' does not appear to use migrations.

我向前推进了应用的指示和初始化迁移。然后我又尝试了--delete-ghost-migrations

/Users/AaronPardes/Dropbox/Python/home_repos/squidtix/squidtix/virtualenvironments/squidtixENV/lib/python2.7/site-packages/django/utils/hashcompat.py:9: DeprecationWarning:  django.utils.hashcompat is deprecated; use hashlib instead
  DeprecationWarning)

Running migrations for tixeng:
- Nothing to migrate.
- Loading initial data for tixeng.
Installed 0 object(s) from 0 fixture(s)

然后,我对模型进行了更改,并尝试为更改创建新的迁移。

^C(squidtixENV)Aarons-MacBook-Pro:squidtix AaronPardes$ ./manage.py schemamigration tixeng --auto
+ Added field for_sale on tixeng.SquidTic
Created 0002_auto__add_field_squidtic_for_sale.py. You can now apply this migration with: ./manage.py migrate tixeng

并应用迁移。

/Users/AaronPardes/Dropbox/Python/home_repos/squidtix/squidtix/virtualenvironments/squidtixENV   /lib/python2.7/site-packages/django/utils/hashcompat.py:9: DeprecationWarning:   django.utils.hashcompat is deprecated; use hashlib instead
  DeprecationWarning)

Running migrations for tixeng:
- Migrating forwards to 0002_auto__add_field_squidtic_for_sale.
> tixeng:0002_auto__add_field_squidtic_for_sale
FATAL ERROR - The following SQL query failed: CREATE TABLE "_south_new_tixeng_squidtic"      ("date_listed" datetime NOT NULL, "event_id" integer NOT NULL, "price" integer NOT NULL, "for_sale" bool NOT NULL DEFAULT 1, "id" integer PRIMARY KEY, "owner_id" integer)
The error was: table "_south_new_tixeng_squidtic" already exists
 ! Error found during real run of migration! Aborting.

 ! Since you have a database that does not support running
 ! schema-altering statements in transactions, we have had 
 ! to leave it in an interim state between migrations.

! You *might* be able to recover with:
 ! The South developers regret this has happened, and would
 ! like to gently persuade you to consider a slightly
 ! easier-to-deal-with DBMS (one that supports DDL transactions)
 ! NOTE: The error which caused the migration to fail is further up.
Error in migration: tixeng:0002_auto__add_field_squidtic_for_sale
DatabaseError: table "_south_new_tixeng_squidtic" already exists

相关信息:

正在添加的字段:models.BooleanField(default = True)

创建的迁移:

# -*- 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 field 'SquidTic.for_sale'
        db.add_column(u'tixeng_squidtic', 'for_sale',
                  self.gf('django.db.models.fields.BooleanField')(default=True),
                  keep_default=False)


    def backwards(self, orm):
        # Deleting field 'SquidTic.for_sale'
        db.delete_column(u'tixeng_squidtic', 'for_sale')


    models = {
        u'accounts.myprofile': {
            'Meta': {'object_name': 'MyProfile'},
            'favourite_snack': ('django.db.models.fields.CharField', [], {'max_length': '5'}),
            u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
            'mugshot': ('django.db.models.fields.files.ImageField', [], {'max_length': '100',  'blank': 'True'}),
            'privacy': ('django.db.models.fields.CharField', [], {'default': "'registered'", 'max_length': '15'}),
            'user': ('django.db.models.fields.related.OneToOneField', [], {'related_name': "'my_profile'", 'unique': 'True', 'to': u"orm['auth.User']"})
        },
        u'auth.group': {
            'Meta': {'object_name': 'Group'},
            u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
            'name': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '80'}),
            'permissions': ('django.db.models.fields.related.ManyToManyField', [], {'to': u"orm['auth.Permission']", 'symmetrical': 'False', 'blank': 'True'})
        },
        u'auth.permission': {
            'Meta': {'ordering': "(u'content_type__app_label', u'content_type__model', u'codename')", 'unique_together': "((u'content_type', u'codename'),)", 'object_name': 'Permission'},
            'codename': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
            'content_type': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['contenttypes.ContentType']"}),
            u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
            'name': ('django.db.models.fields.CharField', [], {'max_length': '50'})
        },
        u'auth.user': {
            'Meta': {'object_name': 'User'},
            'date_joined': ('django.db.models.fields.DateTimeField', [], {'default':   'datetime.datetime.now'}),
            'email': ('django.db.models.fields.EmailField', [], {'max_length': '75', 'blank': 'True'}),
            'first_name': ('django.db.models.fields.CharField', [], {'max_length': '30', 'blank': 'True'}),
            'groups': ('django.db.models.fields.related.ManyToManyField', [], {'to': u"orm['auth.Group']", 'symmetrical': 'False', 'blank': 'True'}),
            u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
            'is_active': ('django.db.models.fields.BooleanField', [], {'default': 'True'}),
            'is_staff': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
            'is_superuser': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
            'last_login': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}),
            'last_name': ('django.db.models.fields.CharField', [], {'max_length': '30', 'blank': 'True'}),
            'password': ('django.db.models.fields.CharField', [], {'max_length': '128'}),
            'user_permissions': ('django.db.models.fields.related.ManyToManyField', [], {'to': u"orm['auth.Permission']", 'symmetrical': 'False', 'blank': 'True'}),
            'username': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '30'})
        },
        u'contenttypes.contenttype': {
            'Meta': {'ordering': "('name',)", 'unique_together': "(('app_label', 'model'),)", 'object_name': 'ContentType', 'db_table': "'django_content_type'"},
            'app_label': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
            u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
            'model': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
            'name': ('django.db.models.fields.CharField', [], {'max_length': '100'})
        },
        u'tixeng.squidartist': {
            'Meta': {'object_name': 'SquidArtist'},
            'artist_name': ('django.db.models.fields.CharField', [], {'max_length': '20'}),
            u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
            'name': ('django.db.models.fields.CharField', [], {'max_length': '20'})
        },
        u'tixeng.squidevent': {
            'Meta': {'object_name': 'SquidEvent'},
            'artist': ('django.db.models.fields.related.ManyToManyField', [], {'to': u"orm['tixeng.SquidArtist']", 'symmetrical': 'False'}),
            'event_date': ('django.db.models.fields.DateTimeField', [], {}),
            u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
            'name': ('django.db.models.fields.CharField', [], {'max_length': '20'}),
            'venue': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['tixeng.SquidVenue']"})
        },
        u'tixeng.squidtic': {
            'Meta': {'object_name': 'SquidTic'},
            'date_listed': ('django.db.models.fields.DateTimeField', [], {}),
            'event': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['tixeng.SquidEvent']"}),
            'for_sale': ('django.db.models.fields.BooleanField', [], {'default': 'True'}),
            u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
            'owner': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['accounts.MyProfile']"}),
            'price': ('django.db.models.fields.IntegerField', [], {'default': '0.0'})
        },
        u'tixeng.squidvenue': {
            'Meta': {'object_name': 'SquidVenue'},
            u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
            'name': ('django.db.models.fields.CharField', [], {'max_length': '20'}),
            'street_address': ('django.db.models.fields.CharField', [], {'max_length': '20'})
        }
    }

    complete_apps = ['tixeng']

2 个答案:

答案 0 :(得分:0)

我会接受一个有根据的猜测:你在南方管理的应用中创建了一个新模型,但是你使用syncdb来创建它的表。现在您可以在此表中添加一个字段,这就是修复它的方法。

  1. 在添加字段之前,请创建架构迁移。它应该使用新的模型表创建迁移。

  2. 使用--fake 应用此新迁移,它不会创建表格,但会告诉南方此迁移已完成。

  3. 现在添加字段,创建架构迁移。它应该创建将字段添加到表中的迁移。

  4. 正常应用此新迁移,无--fake

答案 1 :(得分:0)

所以最后我决定从头开始使用新的数据库。一旦我再次正确设置它,它就完全正常运行了。仍然不确定我的问题是什么,但这解决了它。