web-dev-qa-db-ja.com

Django syncdbと移行

Django Webサイトをあるサーバーから別のサーバーに移動しているので、syncdbを実行しようとしたので、python manage.py syncdb、そして私はこの出力を取得します:

Syncing...
Creating tables ...
The following content types are stale and need to be deleted:

    orders | ordercontact

Any objects related to these content types by a foreign key will also
be deleted. Are you sure you want to delete these content types?
If you're unsure, answer 'no'.

    Type 'yes' to continue, or 'no' to cancel: no
Installing custom SQL ...
Installing indexes ...
No fixtures found.

Synced:
 > Django.contrib.auth
 > Django.contrib.contenttypes
 > Django.contrib.sessions
 > Django.contrib.sites
 > Django.contrib.messages
 > Django.contrib.admin
 > Django.contrib.admindocs
 > Django.contrib.markup
 > Django.contrib.sitemaps
 > Django.contrib.redirects
 > Django_filters
 > freetext
 > sorl.thumbnail
 > Django_extensions
 > south
 > currencies
 > pagination
 > tagging
 > honeypot
 > core
 > faq
 > logentry
 > menus
 > news
 > shop
 > shop.cart
 > shop.orders

Not synced (use migrations):
 - dbtemplates
 - contactform
 - links
 - media
 - pages
 - popularity
 - testimonials
 - shop.brands
 - shop.collections
 - shop.discount
 - shop.pricing
 - shop.product_types
 - shop.products
 - shop.shipping
 - shop.tax
(use ./manage.py migrate to migrate these)

次のステップはpython manage.py migrate、そしてこれは私が持っているものです:

Running migrations for dbtemplates:
 - Migrating forwards to 0002_auto__del_unique_template_name.
 > dbtemplates:0001_initial
 ! 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:   = DROP TABLE `Django_template` CASCADE; []
   = DROP TABLE `Django_template_sites` CASCADE; []

 ! The South developers regret this has happened, and would
 ! like to gently persuade you to consider a slightly
 ! easier-to-deal-with DBMS.
 ! NOTE: The error which caused the migration to fail is further up.
Traceback (most recent call last):
  File "manage.py", line 13, in <module>
    execute_manager(settings)
  File "/usr/lib/python2.6/site-packages/Django/core/management/__init__.py", line 438, in execute_manager
    utility.execute()
  File "/usr/lib/python2.6/site-packages/Django/core/management/__init__.py", line 379, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/usr/lib/python2.6/site-packages/Django/core/management/base.py", line 191, in run_from_argv
    self.execute(*args, **options.__dict__)
  File "/usr/lib/python2.6/site-packages/Django/core/management/base.py", line 220, in execute
    output = self.handle(*args, **options)
  File "/usr/lib/python2.6/site-packages/South-0.7.3-py2.6.Egg/south/management/commands/migrate.py", line 105, in handle
    ignore_ghosts = ignore_ghosts,
  File "/usr/lib/python2.6/site-packages/South-0.7.3-py2.6.Egg/south/migration/__init__.py", line 191, in migrate_app
    success = migrator.migrate_many(target, workplan, database)
  File "/usr/lib/python2.6/site-packages/South-0.7.3-py2.6.Egg/south/migration/migrators.py", line 221, in migrate_many
    result = migrator.__class__.migrate_many(migrator, target, migrations, database)
  File "/usr/lib/python2.6/site-packages/South-0.7.3-py2.6.Egg/south/migration/migrators.py", line 292, in migrate_many
    result = self.migrate(migration, database)
  File "/usr/lib/python2.6/site-packages/South-0.7.3-py2.6.Egg/south/migration/migrators.py", line 125, in migrate
    result = self.run(migration)
  File "/usr/lib/python2.6/site-packages/South-0.7.3-py2.6.Egg/south/migration/migrators.py", line 99, in run
    return self.run_migration(migration)
  File "/usr/lib/python2.6/site-packages/South-0.7.3-py2.6.Egg/south/migration/migrators.py", line 81, in run_migration
    migration_function()
  File "/usr/lib/python2.6/site-packages/South-0.7.3-py2.6.Egg/south/migration/migrators.py", line 57, in <lambda>
    return (lambda: direction(orm))
  File "/usr/lib/python2.6/site-packages/Django_dbtemplates-1.3-py2.6.Egg/dbtemplates/migrations/0001_initial.py", line 18, in forwards
    ('last_changed', self.gf('Django.db.models.fields.DateTimeField')(default=datetime.datetime.now)),
  File "/usr/lib/python2.6/site-packages/South-0.7.3-py2.6.Egg/south/db/generic.py", line 226, in create_table
    ', '.join([col for col in columns if col]),
  File "/usr/lib/python2.6/site-packages/South-0.7.3-py2.6.Egg/south/db/generic.py", line 150, in execute
    cursor.execute(sql, params)
  File "/usr/lib/python2.6/site-packages/Django/db/backends/util.py", line 34, in execute
    return self.cursor.execute(sql, params)
  File "/usr/lib/python2.6/site-packages/Django/db/backends/mysql/base.py", line 86, in execute
    return self.cursor.execute(query, args)
  File "/usr/lib64/python2.6/site-packages/MySQLdb/cursors.py", line 174, in execute
    self.errorhandler(self, exc, value)
  File "/usr/lib64/python2.6/site-packages/MySQLdb/connections.py", line 36, in defaulterrorhandler
    raise errorclass, errorvalue
_mysql_exceptions.OperationalError: (1050, "Table 'Django_template' already exists")

私の質問は、テーブルを削除する必要があるかどうかですDjango_templateおよびDjango_template_sites MySQLから?両方のテーブルが空です。

CentOS 6で実行していますDjango 1.3.1、python 2.6

14
miszczu

試す

syncdb --all 

私は同じ問題を抱えており、すべてがうまくいきます。

私はこの解決策をここに見つけました https://github.com/divio/Django-cms/issues/134

21
Ahmad Ajmi

これは、他の人が同じ問題を経験するのを助けるかもしれません。

これでデータベースが作成され、移行は必要ありません。Ahmadが言ったことを実行した後、偽の移行も実行して、すべての移行スクリプトをすでに実行済みとしてマークしてください。つまり、これらを実行します。

syncdb --all
migrate --fake

データベースにすでにデータがある場合は、syncdb --allを使用しないでください。

15
Henok Getachew
$python manage.py syncdb --migrate

これは移行する必要があるものを移行します

私のために働いた(Django 1.4)

6
Seyhan

もう1つの方法は、最初の移行を完了としてマークすることです。

./manage.py migrate dbtemplates --fake 0001

作成したいスキーマが既にデータベースにあるようです。

1
pyriku