2016-09-15 20 views
0

私はdjangoモデルを使用して2つのテーブルプロファイルと詳細を作成しています。私はDjangoは移行ファイルと移行テーブルを削除した後にデータベーステーブルを作成しません

python2.7 manage.py makemigrations 

python2.7 manage.py migrate 

を使用してテーブルを作成しようとしたとき、私は、移行ファイルを削除し、django_migrationテーブルを切り捨てて は、さらに、それは、テーブルを作成していませんでした。私は、コマンドに与え

python2.7 manage.py runserver 

そのを実行している今、ときに私は

You have unapplied migrations; your app may not work properly until they are applied. 
Run 'python manage.py migrate' to apply them. 

をエラーと私はコマンドエラーを移行manage.pyののpythonを実行する場合

Operations to perform: 
Apply all migrations: home, contenttypes, auth, sessions 
Running migrations: 
Rendering model states... DONE 
Applying contenttypes.0001_initial...Traceback (most recent call last): 
File "manage.py", line 10, in <module> 
execute_from_command_line(sys.argv) 
File "/usr/local/lib/python2.7/dist-packages/django/core/management/__init__.py", line 350, in execute_from_command_line 
utility.execute() 
File "/usr/local/lib/python2.7/dist-packages/django/core/management/__init__.py", line 342, in execute 
self.fetch_command(subcommand).run_from_argv(self.argv) 
File "/usr/local/lib/python2.7/dist-packages/django/core/management/base.py", line 348, in run_from_argv 
self.execute(*args, **cmd_options) 
File "/usr/local/lib/python2.7/dist-packages/django/core/management/base.py", line 399, in execute 
output = self.handle(*args, **options) 
File "/usr/local/lib/python2.7/dist-packages/django/core/management/commands/migrate.py", line 200, in handle 
executor.migrate(targets, plan, fake=fake, fake_initial=fake_initial) 
File "/usr/local/lib/python2.7/dist-packages/django/db/migrations/executor.py", line 92, in migrate 
self._migrate_all_forwards(plan, full_plan, fake=fake, fake_initial=fake_initial) 
File "/usr/local/lib/python2.7/dist-packages/django/db/migrations/executor.py", line 121, in _migrate_all_forwards 
state = self.apply_migration(state, migration, fake=fake, fake_initial=fake_initial) 
File "/usr/local/lib/python2.7/dist-packages/django/db/migrations/executor.py", line 198, in apply_migration 
state = migration.apply(state, schema_editor) 
File "/usr/local/lib/python2.7/dist-packages/django/db/migrations/migration.py", line 123, in apply 
operation.database_forwards(self.app_label, schema_editor, old_state, project_state) 
File "/usr/local/lib/python2.7/dist-packages/django/db/migrations/operations/models.py", line 59, in database_forwards 
schema_editor.create_model(model) 
File "/usr/local/lib/python2.7/dist-packages/django/db/backends/base/schema.py", line 284, in create_model 
self.execute(sql, params or None) 
File "/usr/local/lib/python2.7/dist-packages/django/db/backends/base/schema.py", line 110, in execute 
cursor.execute(sql, params) 
File "/usr/local/lib/python2.7/dist-packages/django/db/backends/utils.py", line 79, in execute 
return super(CursorDebugWrapper, self).execute(sql, params) 
File "/usr/local/lib/python2.7/dist-packages/django/db/backends/utils.py", line 64, in execute 
return self.cursor.execute(sql, params) 
File "/usr/local/lib/python2.7/dist-packages/django/db/utils.py", line 95, in __exit__ 
six.reraise(dj_exc_type, dj_exc_value, traceback) 
File "/usr/local/lib/python2.7/dist-packages/django/db/backends/utils.py", line 62, in execute 
return self.cursor.execute(sql) 
django.db.utils.ProgrammingError: relation "django_content_type" already exists 
+0

今では、すでに私は自分のデータベースの名前を変更することはできませんので、それは?正しい方法です – Pankaj

+0

すべてのテーブルが存在すると、いくつかのデータもある「というdjango_content_type_app_label_76bd3d3b_uniqを示していますどんな代替? – Jan

+0

。あなたはあなたの全体のデータベースの名前を変更して、再度マイグレーションを実行することをお勧めします – Pankaj

答えて

0

次のコマンドを実行します:

python manage.py migrate --fake-initial 
+0

このコマンドを実行した後のエラーは次のとおりです: - django.db.utils.Programm ingError:関係 "django_content_type"の列 "name"が存在しません – Pankaj

+0

一度データベース全体を削除して新しいデータベースを作成してからmigratを実行します – sam

0

最初に偽造する必要がありますこれらの組み込みのアプリケーションのそれぞれの移行は

のpython manage.py移行--fake認証
のpythonは--fakeが初期偽

実行をcontenttypesの移行manage.pyの

python manage.py migrate --fake-initial

これはほとんどの場合、うまくいくはずです。

+0

長いエラーを示す第2のコマンド – Pankaj

+0

@Pankaj何が表示されていますか? – SpiXel

関連する問題