1

以前に25回の移行が成功した既存のDjangoプロジェクトがあります。

モデルの一部のフィールドを、m2mフィールドからテキストフィールドなどのさまざまなタイプに変更しました。現在、これを移行しようとしています。

私は走った:

python manage.py schemamigration backend --auto

その後

python manage.py migrate

そして私は次のようになります

backend:0026_auto__del_vehicle__del_assetproperty__del_liabilityproperty__del_banka致命的なエラー-次のSQLクエリが失敗しました:ALTER TABLE backend_userprofileMODIFY previous_addresslongtext NULL ;; エラーは次のとおりです:(1170、「キーの長さのないキー指定で使用されるBLOB /TEXT列'previous_address'」)!移行の実際の実行中にエラーが見つかりました!中絶。

 ! 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:   = CREATE INDEX `backend_userprofile_a44d8d16` ON `backend_userprofile` (`employer_address_id`); []
   = CREATE INDEX `backend_userprofile_eb751626` ON `backend_userprofile` (`previous_address_id`); []
   = CREATE INDEX `backend_userprofile_174f2184` ON `backend_userprofile` (`employer_phone_id`); []
   = CREATE TABLE `backend_vehicle` (`make` varchar(30) NOT NULL, `financial_status` integer NOT NULL, `values` numeric(30, 2) NOT NULL, `year` date NOT NULL, `model` varchar(30) NOT NULL, `id` integer AUTO_INCREMENT NOT NULL PRIMARY KEY); []
   = CREATE TABLE `backend_assetproperty` (`registered_name` varchar(30) NOT NULL, `id` integer AUTO_INCREMENT NOT NULL PRIMARY KEY, `estimate_value` numeric(30, 2) NOT NULL, `purchase_price` numeric(30, 2) NOT NULL); []
   = CREATE TABLE `backend_liabilityproperty` (`taxes_included` bool NOT NULL, `insured` bool NOT NULL, `monthly_payment` numeric(30, 2) NOT NULL, `payment_type` integer NOT NULL, `landlord` varchar(30) NOT NULL, `property_taxes` numeric(30, 2) NOT NULL, `id` integer AUTO_INCREMENT NOT NULL PRIMARY KEY, `amount_owing` numeric(30, 2) NOT NULL); []
   = CREATE TABLE `backend_bankaccountasset` (`balance` numeric(30, 2) NOT NULL, `id` integer AUTO_INCREMENT NOT NULL PRIMARY KEY, `bank_name` varchar(30) NOT NULL); []
   = CREATE TABLE `backend_credit` (`paid_in_full` bool NOT NULL, `monthly_payment` numeric(30, 2) NOT NULL, `person_business` integer NOT NULL, `balance` numeric(30, 2) NOT NULL, `institution_name` varchar(30) NOT NULL, `id` integer AUTO_INCREMENT NOT NULL PRIMARY KEY, `credit_limit` numeric(30, 2) NOT NULL); []
   = DROP TABLE `backend_liability` CASCADE; []
   = DROP TABLE `backend_asset` CASCADE; []
   = DROP TABLE `backend_otherincome` CASCADE; []
   = ALTER TABLE `backend_userprofile` ADD COLUMN `bank_branch_number` integer NULL; []
   - no dry run output for alter_column() due to dynamic DDL, sorry
   = ALTER TABLE `backend_userprofile` ADD COLUMN `address_id` integer NULL; []
   - no dry run output for alter_column() due to dynamic DDL, sorry
   = ALTER TABLE `backend_userprofile` ADD COLUMN `gross_monthly_income` numeric(30, 2) NULL; []
   - no dry run output for alter_column() due to dynamic DDL, sorry
   = ALTER TABLE `backend_userprofile` ADD COLUMN `other_income` numeric(30, 2) NULL; []
   - no dry run output for alter_column() due to dynamic DDL, sorry
   = ALTER TABLE `backend_userprofile` ADD COLUMN `bank_phone_id` integer NULL; []
   - no dry run output for alter_column() due to dynamic DDL, sorry
   = ALTER TABLE `backend_userprofile` ADD COLUMN `bank_contact_details_id` integer NULL; []
   - no dry run output for alter_column() due to dynamic DDL, sorry
   - no dry run output for delete_foreign_key() due to dynamic DDL, sorry
   = ALTER TABLE `backend_userprofile` DROP COLUMN `current_address` CASCADE; []
   - no dry run output for delete_foreign_key() due to dynamic DDL, sorry
   = ALTER TABLE `backend_userprofile` DROP COLUMN `current_unit_number` CASCADE; []
   - no dry run output for delete_foreign_key() due to dynamic DDL, sorry
   = ALTER TABLE `backend_userprofile` DROP COLUMN `current_city` CASCADE; []
   - no dry run output for delete_foreign_key() due to dynamic DDL, sorry
   = ALTER TABLE `backend_userprofile` DROP COLUMN `current_province` CASCADE; []
   - no dry run output for delete_foreign_key() due to dynamic DDL, sorry
   = ALTER TABLE `backend_userprofile` DROP COLUMN `current_postal_code` CASCADE; []
   - no dry run output for delete_foreign_key() due to dynamic DDL, sorry
   = ALTER TABLE `backend_userprofile` DROP COLUMN `current_time_at_residence` CASCADE; []
   - no dry run output for delete_foreign_key() due to dynamic DDL, sorry
   = ALTER TABLE `backend_userprofile` DROP COLUMN `previous_unit_number` CASCADE; []
   - no dry run output for delete_foreign_key() due to dynamic DDL, sorry
   = ALTER TABLE `backend_userprofile` DROP COLUMN `previous_city` CASCADE; []
   - no dry run output for delete_foreign_key() due to dynamic DDL, sorry
   = ALTER TABLE `backend_userprofile` DROP COLUMN `previous_province` CASCADE; []
   - no dry run output for delete_foreign_key() due to dynamic DDL, sorry
   = ALTER TABLE `backend_userprofile` DROP COLUMN `previous_postal_code` CASCADE; []
   - no dry run output for delete_foreign_key() due to dynamic DDL, sorry
   = ALTER TABLE `backend_userprofile` DROP COLUMN `employment_position` CASCADE; []
   - no dry run output for delete_foreign_key() due to dynamic DDL, sorry
   = ALTER TABLE `backend_userprofile` DROP COLUMN `employmer_manager_name` CASCADE; []
   - no dry run output for delete_foreign_key() due to dynamic DDL, sorry
   = ALTER TABLE `backend_userprofile` DROP COLUMN `employment_duration_years` CASCADE; []
   - no dry run output for delete_foreign_key() due to dynamic DDL, sorry
   = ALTER TABLE `backend_userprofile` DROP COLUMN `employment_duration_months` CASCADE; []
   - no dry run output for delete_foreign_key() due to dynamic DDL, sorry
   = ALTER TABLE `backend_userprofile` DROP COLUMN `employer_unit_number` CASCADE; []
   - no dry run output for delete_foreign_key() due to dynamic DDL, sorry
   = ALTER TABLE `backend_userprofile` DROP COLUMN `employer_city` CASCADE; []
   - no dry run output for delete_foreign_key() due to dynamic DDL, sorry
   = ALTER TABLE `backend_userprofile` DROP COLUMN `employer_province` CASCADE; []
   - no dry run output for delete_foreign_key() due to dynamic DDL, sorry
   = ALTER TABLE `backend_userprofile` DROP COLUMN `employer_postal_code` CASCADE; []
   - no dry run output for delete_foreign_key() due to dynamic DDL, sorry
   = ALTER TABLE `backend_userprofile` DROP COLUMN `previous_employment_type` CASCADE; []
   - no dry run output for delete_foreign_key() due to dynamic DDL, sorry
   = ALTER TABLE `backend_userprofile` DROP COLUMN `previous_employer_phone` CASCADE; []
   - no dry run output for delete_foreign_key() due to dynamic DDL, sorry
   = ALTER TABLE `backend_userprofile` DROP COLUMN `previous_employer_address` CASCADE; []
   - no dry run output for delete_foreign_key() due to dynamic DDL, sorry
   = ALTER TABLE `backend_userprofile` DROP COLUMN `previous_employer_unit_number` CASCADE; []
   - no dry run output for delete_foreign_key() due to dynamic DDL, sorry
   = ALTER TABLE `backend_userprofile` DROP COLUMN `previous_employer_city` CASCADE; []
   - no dry run output for delete_foreign_key() due to dynamic DDL, sorry
   = ALTER TABLE `backend_userprofile` DROP COLUMN `previous_employer_province` CASCADE; []
   - no dry run output for delete_foreign_key() due to dynamic DDL, sorry
   = ALTER TABLE `backend_userprofile` DROP COLUMN `previous_employer_postal_code` CASCADE; []
   - no dry run output for delete_foreign_key() due to dynamic DDL, sorry
   = ALTER TABLE `backend_userprofile` DROP COLUMN `employment_monthly_income` CASCADE; []
   - no dry run output for delete_foreign_key() due to dynamic DDL, sorry
   = ALTER TABLE `backend_userprofile` DROP COLUMN `bank_contact_phone` CASCADE; []
   - no dry run output for delete_foreign_key() due to dynamic DDL, sorry
   = ALTER TABLE `backend_userprofile` DROP COLUMN `bank_contact_fax` CASCADE; []
   - no dry run output for delete_foreign_key() due to dynamic DDL, sorry
   = ALTER TABLE `backend_userprofile` DROP COLUMN `bank_institution_number` CASCADE; []
   - no dry run output for delete_foreign_key() due to dynamic DDL, sorry
   = ALTER TABLE `backend_userprofile` DROP COLUMN `bank_transit_number` CASCADE; []
   - no dry run output for delete_foreign_key() due to dynamic DDL, sorry
   = ALTER TABLE `backend_userprofile` DROP COLUMN `bank_address` CASCADE; []
   - no dry run output for delete_foreign_key() due to dynamic DDL, sorry
   = ALTER TABLE `backend_userprofile` DROP COLUMN `bank_unit_number` CASCADE; []
   - no dry run output for delete_foreign_key() due to dynamic DDL, sorry
   = ALTER TABLE `backend_userprofile` DROP COLUMN `bank_city` CASCADE; []
   - no dry run output for delete_foreign_key() due to dynamic DDL, sorry
   = ALTER TABLE `backend_userprofile` DROP COLUMN `bank_province` CASCADE; []
   - no dry run output for delete_foreign_key() due to dynamic DDL, sorry
   = ALTER TABLE `backend_userprofile` DROP COLUMN `bank_postal_code` CASCADE; []
   - no dry run output for delete_foreign_key() due to dynamic DDL, sorry
   = ALTER TABLE `backend_userprofile` DROP COLUMN `residence_type` CASCADE; []
   - no dry run output for delete_foreign_key() due to dynamic DDL, sorry
   = ALTER TABLE `backend_userprofile` DROP COLUMN `residence_value` CASCADE; []
   - no dry run output for delete_foreign_key() due to dynamic DDL, sorry
   = ALTER TABLE `backend_userprofile` DROP COLUMN `residence_monthly_payment` CASCADE; []
   - no dry run output for delete_foreign_key() due to dynamic DDL, sorry
   = ALTER TABLE `backend_userprofile` DROP COLUMN `claimed_bankruptcy` CASCADE; []
   - no dry run output for delete_foreign_key() due to dynamic DDL, sorry
   = ALTER TABLE `backend_userprofile` DROP COLUMN `fraud_alerts` CASCADE; []
   - no dry run output for delete_foreign_key() due to dynamic DDL, sorry
   = ALTER TABLE `backend_userprofile` DROP COLUMN `credit_consent` CASCADE; []
   - no dry run output for delete_foreign_key() due to dynamic DDL, sorry
   = ALTER TABLE `backend_userprofile` DROP COLUMN `notes` CASCADE; []
   - no dry run output for delete_foreign_key() due to dynamic DDL, sorry
   = ALTER TABLE `backend_userprofile` DROP COLUMN `signature` CASCADE; []
   - no dry run output for delete_foreign_key() due to dynamic DDL, sorry
   = ALTER TABLE `backend_userprofile` DROP COLUMN `cobuyer_relationship` CASCADE; []
   - no dry run output for delete_foreign_key() due to dynamic DDL, sorry
   = ALTER TABLE `backend_userprofile` DROP COLUMN `cobuyer_other` CASCADE; []
   = CREATE TABLE `backend_userprofile_vehicles` (`id` integer AUTO_INCREMENT NOT NULL PRIMARY KEY, `userprofile_id` integer NOT NULL, `vehicle_id` integer NOT NULL); []
   = ALTER TABLE `backend_userprofile_vehicles` ADD CONSTRAINT `backend_userprofile_vehicl_userprofile_id_2118f7c8e02a7a01_uniq` UNIQUE (`userprofile_id`, `vehicle_id`) []
   = CREATE TABLE `backend_userprofile_bank_accounts_asset` (`id` integer AUTO_INCREMENT NOT NULL PRIMARY KEY, `userprofile_id` integer NOT NULL, `bankaccountasset_id` integer NOT NULL); []
   = ALTER TABLE `backend_userprofile_bank_accounts_asset` ADD CONSTRAINT `backend_userprofile_bank_a_userprofile_id_3780e7dea36fdd1b_uniq` UNIQUE (`userprofile_id`, `bankaccountasset_id`) []
   = CREATE TABLE `backend_userprofile_credit` (`id` integer AUTO_INCREMENT NOT NULL PRIMARY KEY, `userprofile_id` integer NOT NULL, `credit_id` integer NOT NULL); []
   = ALTER TABLE `backend_userprofile_credit` ADD CONSTRAINT `backend_userprofile_credit_userprofile_id_aa5c94a808f9fb7_uniq` UNIQUE (`userprofile_id`, `credit_id`) []
   = CREATE TABLE `backend_userprofile_property_asset` (`id` integer AUTO_INCREMENT NOT NULL PRIMARY KEY, `userprofile_id` integer NOT NULL, `assetproperty_id` integer NOT NULL); []
   = ALTER TABLE `backend_userprofile_property_asset` ADD CONSTRAINT `backend_userprofile_proper_userprofile_id_3397e38f7c83f4db_uniq` UNIQUE (`userprofile_id`, `assetproperty_id`) []
   = CREATE TABLE `backend_userprofile_liability_properties` (`id` integer AUTO_INCREMENT NOT NULL PRIMARY KEY, `userprofile_id` integer NOT NULL, `liabilityproperty_id` integer NOT NULL); []
   = ALTER TABLE `backend_userprofile_liability_properties` ADD CONSTRAINT `backend_userprofile_liabil_userprofile_id_21457cbf6edd1007_uniq` UNIQUE (`userprofile_id`, `liabilityproperty_id`) []
   = DROP TABLE `backend_userprofile_other_income` CASCADE; []
   = DROP TABLE `backend_userprofile_assets` CASCADE; []
   = DROP TABLE `backend_userprofile_liabilities` CASCADE; []
   = 
            SELECT kc.`constraint_name`, kc.`column_name`, kc.`table_name`,
                kc.`referenced_table_name`, kc.`referenced_column_name`
            FROM information_schema.key_column_usage AS kc
            WHERE
                kc.table_schema = %s
         ['pomelo_walker']
   - no dry run output for delete_foreign_key() due to dynamic DDL, sorry
   - no dry run output for alter_column() due to dynamic DDL, sorry
   = 
            SELECT kc.`constraint_name`, kc.`column_name`, kc.`table_name`,
                kc.`referenced_table_name`, kc.`referenced_column_name`
            FROM information_schema.key_column_usage AS kc
            WHERE
                kc.table_schema = %s
         ['pomelo_walker']
   - no dry run output for delete_foreign_key() due to dynamic DDL, sorry
   - no dry run output for alter_column() due to dynamic DDL, sorry
   = 
            SELECT kc.`constraint_name`, kc.`column_name`, kc.`table_name`,
                kc.`referenced_table_name`, kc.`referenced_column_name`
            FROM information_schema.key_column_usage AS kc
            WHERE
                kc.table_schema = %s
         ['pomelo_walker']
   - no dry run output for delete_foreign_key() due to dynamic DDL, sorry
   - no dry run output for alter_column() due to dynamic DDL, sorry

 ! 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: backend:0026_auto__del_vehicle__del_assetproperty__del_liabilityproperty__del_banka
Traceback (most recent call last):
  File "manage.py", line 10, in <module>
    execute_from_command_line(sys.argv)
  File "/Users/chungwu/.virtualenvs/walkerfinancial/lib/python2.7/site-packages/django/core/management/__init__.py", line 443, in execute_from_command_line
    utility.execute()
  File "/Users/chungwu/.virtualenvs/walkerfinancial/lib/python2.7/site-packages/django/core/management/__init__.py", line 382, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/Users/chungwu/.virtualenvs/walkerfinancial/lib/python2.7/site-packages/django/core/management/base.py", line 196, in run_from_argv
    self.execute(*args, **options.__dict__)
  File "/Users/chungwu/.virtualenvs/walkerfinancial/lib/python2.7/site-packages/django/core/management/base.py", line 232, in execute
    output = self.handle(*args, **options)
  File "/Users/chungwu/.virtualenvs/walkerfinancial/lib/python2.7/site-packages/south/management/commands/migrate.py", line 108, in handle
    ignore_ghosts = ignore_ghosts,
  File "/Users/chungwu/.virtualenvs/walkerfinancial/lib/python2.7/site-packages/south/migration/__init__.py", line 213, in migrate_app
    success = migrator.migrate_many(target, workplan, database)
  File "/Users/chungwu/.virtualenvs/walkerfinancial/lib/python2.7/site-packages/south/migration/migrators.py", line 235, in migrate_many
    result = migrator.__class__.migrate_many(migrator, target, migrations, database)
  File "/Users/chungwu/.virtualenvs/walkerfinancial/lib/python2.7/site-packages/south/migration/migrators.py", line 310, in migrate_many
    result = self.migrate(migration, database)
  File "/Users/chungwu/.virtualenvs/walkerfinancial/lib/python2.7/site-packages/south/migration/migrators.py", line 133, in migrate
    result = self.run(migration)
  File "/Users/chungwu/.virtualenvs/walkerfinancial/lib/python2.7/site-packages/south/migration/migrators.py", line 107, in run
    return self.run_migration(migration)
  File "/Users/chungwu/.virtualenvs/walkerfinancial/lib/python2.7/site-packages/south/migration/migrators.py", line 81, in run_migration
    migration_function()
  File "/Users/chungwu/.virtualenvs/walkerfinancial/lib/python2.7/site-packages/south/migration/migrators.py", line 57, in <lambda>
    return (lambda: direction(orm))
  File "/Users/chungwu/Sites/pomelo/walkerfinancial/backend/migrations/0026_auto__del_vehicle__del_assetproperty__del_liabilityproperty__del_banka.py", line 347, in forwards
    db.alter_column('backend_userprofile', 'previous_address', self.gf('django.db.models.fields.TextField')(null=True))
  File "/Users/chungwu/.virtualenvs/walkerfinancial/lib/python2.7/site-packages/south/db/generic.py", line 44, in _cache_clear
    return func(self, table, *args, **opts)
  File "/Users/chungwu/.virtualenvs/walkerfinancial/lib/python2.7/site-packages/south/db/generic.py", line 527, in alter_column
    self.execute("ALTER TABLE %s %s;" % (self.quote_name(table_name), sql), values)
  File "/Users/chungwu/.virtualenvs/walkerfinancial/lib/python2.7/site-packages/south/db/generic.py", line 273, in execute
    cursor.execute(sql, params)
  File "/Users/chungwu/.virtualenvs/walkerfinancial/lib/python2.7/site-packages/django/db/backends/util.py", line 40, in execute
    return self.cursor.execute(sql, params)
  File "/Users/chungwu/.virtualenvs/walkerfinancial/lib/python2.7/site-packages/django/db/backends/mysql/base.py", line 114, in execute
    return self.cursor.execute(query, args)
  File "/Users/chungwu/.virtualenvs/walkerfinancial/lib/python2.7/site-packages/MySQLdb/cursors.py", line 201, in execute
    self.errorhandler(self, exc, value)
  File "/Users/chungwu/.virtualenvs/walkerfinancial/lib/python2.7/site-packages/MySQLdb/connections.py", line 36, in defaulterrorhandler
    raise errorclass, errorvalue
django.db.utils.DatabaseError: (1170, "BLOB/TEXT column 'previous_address' used in key specification without a key length")

これを解決する方法はありますか?

Django1.4.5とSouth0.7.6を実行しています

4

1 に答える 1

3

まず、アプリの移行フォルダーから最後の移行を削除します。

次に、m2mフィールドを削除し、移行を作成してから、新しいテキストフィールドを追加して、別の移行を作成することをお勧めします。2つのステップで処理すれば、Southはこのプロセスを処理できるはずだと思います。

于 2013-02-27T16:08:47.173 に答える