2016-12-17 1 views
0

こんにちは、お時間djangoの移行エラー(NOT NULL制約に失敗しました)を修正するにはどうすればよいですか?

状況のためにあなたに感謝:私は私のDjangoのモデルにつの新しいフィールドを追加する必要がある

status_of_lieman = models.BooleanField(default=False, verbose_name="Course status") 

Makemigratiosは罰金行くフィールドが、移行しようとするとエラーが表示されます:

Running migrations: 
    Applying faceset.0077_course_status_of_lieman...Traceback (most recent call last): 
    File "C:\python35\lib\site-packages\django\db\backends\utils.py", line 64, in execute 
    return self.cursor.execute(sql, params) 
    File "C:\python35\lib\site-packages\django\db\backends\sqlite3\base.py", line 323, in execute 
    return Database.Cursor.execute(self, query, params) 
sqlite3.IntegrityError: NOT NULL constraint failed: faceset_course.status_of_lieman 

The above exception was the direct cause of the following exception: 

Traceback (most recent call last): 
    File "C:\Program Files (x86)\JetBrains\PyCharm 5.0.4\helpers\pycharm\django_manage.py", line 41, in <module> 
    run_module(manage_file, None, '__main__', True) 
    File "C:\python35\lib\runpy.py", line 182, in run_module 
    return _run_module_code(code, init_globals, run_name, mod_spec) 
    File "C:\python35\lib\runpy.py", line 96, in _run_module_code 
    mod_name, mod_spec, pkg_name, script_name) 
    File "C:\python35\lib\runpy.py", line 85, in _run_code 
    exec(code, run_globals) 
    File "E:/lieman\manage.py", line 10, in <module> 
    execute_from_command_line(sys.argv) 
    File "C:\python35\lib\site-packages\django\core\management\__init__.py", line 353, in execute_from_command_line 
    utility.execute() 
    File "C:\python35\lib\site-packages\django\core\management\__init__.py", line 345, in execute 
    self.fetch_command(subcommand).run_from_argv(self.argv) 
    File "C:\python35\lib\site-packages\django\core\management\base.py", line 348, in run_from_argv 
    self.execute(*args, **cmd_options) 
    File "C:\python35\lib\site-packages\django\core\management\base.py", line 399, in execute 
    output = self.handle(*args, **options) 
    File "C:\python35\lib\site-packages\django\core\management\commands\migrate.py", line 200, in handle 
    executor.migrate(targets, plan, fake=fake, fake_initial=fake_initial) 
    File "C:\python35\lib\site-packages\django\db\migrations\executor.py", line 92, in migrate 
    self._migrate_all_forwards(plan, full_plan, fake=fake, fake_initial=fake_initial) 
    File "C:\python35\lib\site-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 "C:\python35\lib\site-packages\django\db\migrations\executor.py", line 198, in apply_migration 
    state = migration.apply(state, schema_editor) 
    File "C:\python35\lib\site-packages\django\db\migrations\migration.py", line 123, in apply 
    operation.database_forwards(self.app_label, schema_editor, old_state, project_state) 
    File "C:\python35\lib\site-packages\django\db\migrations\operations\fields.py", line 62, in database_forwards 
    field, 
    File "C:\python35\lib\site-packages\django\db\backends\sqlite3\schema.py", line 221, in add_field 
    self._remake_table(model, create_fields=[field]) 
    File "C:\python35\lib\site-packages\django\db\backends\sqlite3\schema.py", line 189, in _remake_table 
    self.quote_name(model._meta.db_table), 
    File "C:\python35\lib\site-packages\django\db\backends\base\schema.py", line 110, in execute 
    cursor.execute(sql, params) 
    File "C:\python35\lib\site-packages\django\db\backends\utils.py", line 79, in execute 
    return super(CursorDebugWrapper, self).execute(sql, params) 
    File "C:\python35\lib\site-packages\django\db\backends\utils.py", line 64, in execute 
    return self.cursor.execute(sql, params) 
    File "C:\python35\lib\site-packages\django\db\utils.py", line 95, in __exit__ 
    six.reraise(dj_exc_type, dj_exc_value, traceback) 
    File "C:\python35\lib\site-packages\django\utils\six.py", line 685, in reraise 
    raise value.with_traceback(tb) 
    File "C:\python35\lib\site-packages\django\db\backends\utils.py", line 64, in execute 
    return self.cursor.execute(sql, params) 
    File "C:\python35\lib\site-packages\django\db\backends\sqlite3\base.py", line 323, in execute 
    return Database.Cursor.execute(self, query, params) 
django.db.utils.IntegrityError: NOT NULL constraint failed: faceset_course.status_of_lieman 

この問題を解決するにはどうすればよいですか?私は、すべての移行を削除してやることができます。しかし、私はこのモードですべての情報を削除するので、私はそれを行うことはできません。

+1

フィールドを追加する移行を表示できますか? – knbk

答えて

0

あなたの移行では、db内にすでに作成されているこのフィールドを持つオブジェクトの値は設定されていない可能性があります。おそらく、最後のマイグレーションファイルを削除し、モデルフィールドでnull = Trueを設定して、マイグレーションを再度実行する必要があります。

関連する問題