Skip to content
This repository has been archived by the owner on Sep 18, 2018. It is now read-only.

在执行 ./manage.py migrate --all 时,出错 #472

Open
alonemen opened this issue Aug 20, 2018 · 1 comment
Open

在执行 ./manage.py migrate --all 时,出错 #472

alonemen opened this issue Aug 20, 2018 · 1 comment

Comments

@alonemen
Copy link

系统:centos7.4
数据库:mysql5.7.14
ratticdb: 1.3.1

执行./manage.py rsyncdb正常,执行./manage.py migrate --all 出错
报错记录:

[root@password RatticWeb]# ./manage.py migrate
Running migrations for user_sessions:
 - Migrating forwards to 0001_initial.
 > user_sessions:0001_initial
 - Loading initial data for user_sessions.
Installed 0 object(s) from 0 fixture(s)
Running migrations for otp_totp:
 - Migrating forwards to 0002_last_t.
 > otp_totp:0001_initial
 > otp_totp:0002_last_t
 - Loading initial data for otp_totp.
Installed 0 object(s) from 0 fixture(s)
Running migrations for two_factor:
 - Migrating forwards to 0005_auto__del_token__del_verifiedcomputer.
 > two_factor:0001_initial
 > two_factor:0002_auto__chg_field_token_seed
 > two_factor:0003_add_model_phone_device
 > two_factor:0004_v012_to_v020
 - Migration 'two_factor:0004_v012_to_v020' is marked for no-dry-run.
 > two_factor:0005_auto__del_token__del_verifiedcomputer
 - Loading initial data for two_factor.
Installed 0 object(s) from 0 fixture(s)
? You have no migrations for the 'django' app. You might want some.
? You have no migrations for the 'djcelery' app. You might want some.
Running migrations for database_files:
 - Migrating forwards to 0001_initial.
 > database_files:0001_initial
 - Loading initial data for database_files.
Installed 0 object(s) from 0 fixture(s)
Running migrations for social_auth:
 - Migrating forwards to 0002_auto__add_unique_nonce_timestamp_salt_server_url__add_unique_associati.
 > social_auth:0001_initial
 > social_auth:0002_auto__add_unique_nonce_timestamp_salt_server_url__add_unique_associati
 - Loading initial data for social_auth.
Installed 0 object(s) from 0 fixture(s)
Running migrations for cred:
 - Migrating forwards to 0034_auto__add_field_cred_ssh_key__add_field_cred_ssh_key_name.
 > cred:0001_initial
 > cred:0002_auto__add_credaudit
 > cred:0003_auto__add_category
 > cred:0004_auto__add_field_cred_category
 > cred:0005_auto__del_field_category_parent
 > cred:0006_auto__del_category__add_tag__chg_field_cred_category
 > cred:0007_auto__add_credchangeq
 > cred:0008_auto
 > cred:0009_auto__del_field_cred_category
 > cred:0010_auto__add_unique_credchangeq_cred
 > cred:0011_auto__add_credicon
 > cred:0012_load_initial_images
 - Migration 'cred:0012_load_initial_images' is marked for no-dry-run.
 > cred:0013_auto__add_field_cred_icon
 > cred:0014_auto__add_unique_credicon_name
 > cred:0015_auto__add_field_credicon_xoffset__add_field_credicon_yoffset
 > cred:0016_remove_broken_icons
 - Migration 'cred:0016_remove_broken_icons' is marked for no-dry-run.
 > cred:0017_reimport_new_icons
 - Migration 'cred:0017_reimport_new_icons' is marked for no-dry-run.
 > cred:0018_fix_unicode_filename
 - Migration 'cred:0018_fix_unicode_filename' is marked for no-dry-run.
 > cred:0019_auto__add_field_cred_is_deleted
 > cred:0020_auto__add_field_cred_url
 > cred:0021_auto__add_field_cred_latest__add_field_cred_created
 > cred:0022_auto__add_field_cred_iconname
 > cred:0023_auto__del_credicon__del_field_cred_icon
 > cred:0024_auto__add_field_cred_descriptionmarkdown
 > cred:0025_auto
 > cred:0026_auto
 > cred:0027_auto__add_field_cred_modified
 > cred:0028_auto__add_index_cred_username
 > cred:0029_auto__add_field_cred_attachment__add_field_cred_attachment_name
 > cred:0030_auto__chg_field_cred_attachment
 > cred:0031_auto__del_index_tag_name__add_unique_tag_name
 > cred:0032_auto__chg_field_cred_password
 > cred:0033_auto__add_table_cred_groups
 > cred:0034_auto__add_field_cred_ssh_key__add_field_cred_ssh_key_name
 - Loading initial data for cred.
Installed 0 object(s) from 0 fixture(s)
Running migrations for account:
 - Migrating forwards to 0010_set_expiry_for_existing_keys.
 > tastypie:0001_initial
 > tastypie:0002_add_apikey_index
 > account:0001_initial
 > account:0002_auto__add_field_userprofile_tags_on_sidebar
 > account:0003_auto__add_field_userprofile_password_changed
 > account:0004_auto
 > account:0005_auto__del_field_userprofile_tags_on_sidebar
 > account:0006_auto__add_apikey
 > account:0007_auto__chg_field_apikey_user__del_unique_apikey_user
FATAL ERROR - The following SQL query failed: ALTER TABLE `account_apikey` DROP INDEX `user_id`
The error was: (1553, "Cannot drop index 'user_id': needed in a foreign key constraint")
 ! 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:   - no dry run output for alter_column() due to dynamic DDL, sorry
   = ALTER TABLE `account_apikey` ADD CONSTRAINT `account_apikey_user_id_1de0096d7d233874_uniq` UNIQUE (`user_id`) []

 ! 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: account:0007_auto__chg_field_apikey_user__del_unique_apikey_user
Traceback (most recent call last):
  File "./manage.py", line 10, in <module>
    execute_from_command_line(sys.argv)
  File "/usr/lib/python2.7/site-packages/django/core/management/__init__.py", line 399, in execute_from_command_line
    utility.execute()
  File "/usr/lib/python2.7/site-packages/django/core/management/__init__.py", line 392, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/usr/lib/python2.7/site-packages/django/core/management/base.py", line 242, in run_from_argv
    self.execute(*args, **options.__dict__)
  File "/usr/lib/python2.7/site-packages/django/core/management/base.py", line 285, in execute
    output = self.handle(*args, **options)
  File "/usr/lib/python2.7/site-packages/south/management/commands/migrate.py", line 111, in handle
    ignore_ghosts = ignore_ghosts,
  File "/usr/lib/python2.7/site-packages/south/migration/__init__.py", line 220, in migrate_app
    success = migrator.migrate_many(target, workplan, database)
  File "/usr/lib/python2.7/site-packages/south/migration/migrators.py", line 254, in migrate_many
    result = migrator.__class__.migrate_many(migrator, target, migrations, database)
  File "/usr/lib/python2.7/site-packages/south/migration/migrators.py", line 329, in migrate_many
    result = self.migrate(migration, database)
  File "/usr/lib/python2.7/site-packages/south/migration/migrators.py", line 133, in migrate
    result = self.run(migration, database)
  File "/usr/lib/python2.7/site-packages/south/migration/migrators.py", line 114, in run
    return self.run_migration(migration, database)
  File "/usr/lib/python2.7/site-packages/south/migration/migrators.py", line 84, in run_migration
    migration_function()
  File "/usr/lib/python2.7/site-packages/south/migration/migrators.py", line 60, in <lambda>
    return (lambda: direction(orm))
  File "/opt/apps/RatticWeb/account/migrations/0007_auto__chg_field_apikey_user__del_unique_apikey_user.py", line 12, in forwards
    db.delete_unique('account_apikey', ['user_id'])
  File "/usr/lib/python2.7/site-packages/south/db/generic.py", line 47, in _cache_clear
    return func(self, table, *args, **opts)
  File "/usr/lib/python2.7/site-packages/south/db/generic.py", line 648, in delete_unique
    self.quote_name(constraint),
  File "/usr/lib/python2.7/site-packages/south/db/generic.py", line 282, in execute
    cursor.execute(sql, params)
  File "/usr/lib/python2.7/site-packages/django/db/backends/util.py", line 53, in execute
    return self.cursor.execute(sql, params)
  File "/usr/lib/python2.7/site-packages/django/db/utils.py", line 99, in __exit__
    six.reraise(dj_exc_type, dj_exc_value, traceback)
  File "/usr/lib/python2.7/site-packages/django/db/backends/util.py", line 53, in execute
    return self.cursor.execute(sql, params)
  File "/usr/lib/python2.7/site-packages/django/db/backends/mysql/base.py", line 124, in execute
    return self.cursor.execute(query, args)
  File "/usr/lib64/python2.7/site-packages/MySQLdb/cursors.py", line 205, in execute
    self.errorhandler(self, exc, value)
  File "/usr/lib64/python2.7/site-packages/MySQLdb/connections.py", line 36, in defaulterrorhandler
    raise errorclass, errorvalue
django.db.utils.OperationalError: (1553, "Cannot drop index 'user_id': needed in a foreign key constraint")

期待 有回复。
thanks

@almeidajeff
Copy link

Hi,
try run

./manage.py syncdb
./manage.py migrate
./manage.py collectstatic
./manage.py compilemessages

By the log it seems to me that Django has not yet created the users table and is not able to relate the field user_id

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants