Django1.6->2.0にアップデートしたらマイグレーション時に django.db.utils.InternalError: (1364, "Field 'name' doesn't have a default value")

Django
2018-01-11 14:48 (6年前) ytyng
View in English

Python2.7 + Django 1.6 のプロジェクトを、Python3.5 + Django2.0 にしてマイグレーションファイルを作り直し、./manage.py migrate したら

django.db.utils.InternalError: (1364, "Field 'name' doesn't have a default value")

のエラーが出た。

ContentType モデルを作る時 ( DBのテーブル名は django_content_type ) に出ているようだ。

取り急ぎ進めたかったので、django_content_type テーブルの name のデフォルト値を '-' なんかにSQLでアップデートすると、一応エラーは出なくなる。

$ ./manage.py dbshell
mysql> ALTER TABLE django_content_type ALTER COLUMN name SET DEFAULT '-';

トレースバック

Traceback (most recent call last):
File "./manage.py", line 11, in <module>
execute_from_command_line(sys.argv)
File "/home/ubuntu/myapp-env/lib/python3.5/site-packages/django/core/management/__init__.py", line 371, in execute_from_command_line
utility.execute()
File "/home/ubuntu/myapp-env/lib/python3.5/site-packages/django/core/management/__init__.py", line 365, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/home/ubuntu/myapp-env/lib/python3.5/site-packages/django/core/management/base.py", line 288, in run_from_argv
self.execute(*args, **cmd_options)
File "/home/ubuntu/myapp-env/lib/python3.5/site-packages/django/core/management/base.py", line 335, in execute
output = self.handle(*args, **options)
File "/home/ubuntu/myapp-env/lib/python3.5/site-packages/django/core/management/commands/migrate.py", line 223, in handle
self.verbosity, self.interactive, connection.alias, apps=post_migrate_apps, plan=plan,
File "/home/ubuntu/myapp-env/lib/python3.5/site-packages/django/core/management/sql.py", line 51, in emit_post_migrate_signal
**kwargs
File "/home/ubuntu/myapp-env/lib/python3.5/site-packages/django/dispatch/dispatcher.py", line 178, in send
for receiver in self._live_receivers(sender)
File "/home/ubuntu/myapp-env/lib/python3.5/site-packages/django/dispatch/dispatcher.py", line 178, in <listcomp>
for receiver in self._live_receivers(sender)
File "/home/ubuntu/myapp-env/lib/python3.5/site-packages/django/contrib/auth/management/__init__.py", line 59, in create_permissions
ctype = ContentType.objects.db_manager(using).get_for_model(klass)
File "/home/ubuntu/myapp-env/lib/python3.5/site-packages/django/contrib/contenttypes/models.py", line 57, in get_for_model
model=opts.model_name,
File "/home/ubuntu/myapp-env/lib/python3.5/site-packages/django/db/models/manager.py", line 82, in manager_method
return getattr(self.get_queryset(), name)(*args, **kwargs)
File "/home/ubuntu/myapp-env/lib/python3.5/site-packages/django/db/models/query.py", line 489, in get_or_create
return self._create_object_from_params(lookup, params)
File "/home/ubuntu/myapp-env/lib/python3.5/site-packages/django/db/models/query.py", line 521, in _create_object_from_params
obj = self.create(**params)
File "/home/ubuntu/myapp-env/lib/python3.5/site-packages/django/db/models/query.py", line 417, in create
obj.save(force_insert=True, using=self.db)
File "/home/ubuntu/myapp-env/lib/python3.5/site-packages/django/db/models/base.py", line 729, in save
force_update=force_update, update_fields=update_fields)
File "/home/ubuntu/myapp-env/lib/python3.5/site-packages/django/db/models/base.py", line 759, in save_base
updated = self._save_table(raw, cls, force_insert, force_update, using, update_fields)
File "/home/ubuntu/myapp-env/lib/python3.5/site-packages/django/db/models/base.py", line 842, in _save_table
result = self._do_insert(cls._base_manager, using, fields, update_pk, raw)
File "/home/ubuntu/myapp-env/lib/python3.5/site-packages/django/db/models/base.py", line 880, in _do_insert
using=using, raw=raw)
File "/home/ubuntu/myapp-env/lib/python3.5/site-packages/django/db/models/manager.py", line 82, in manager_method
return getattr(self.get_queryset(), name)(*args, **kwargs)
File "/home/ubuntu/myapp-env/lib/python3.5/site-packages/django/db/models/query.py", line 1125, in _insert
return query.get_compiler(using=using).execute_sql(return_id)
File "/home/ubuntu/myapp-env/lib/python3.5/site-packages/django/db/models/sql/compiler.py", line 1281, in execute_sql
cursor.execute(sql, params)
File "/home/ubuntu/myapp-env/lib/python3.5/site-packages/django/db/backends/utils.py", line 100, in execute
return super().execute(sql, params)
File "/home/ubuntu/myapp-env/lib/python3.5/site-packages/django/db/backends/utils.py", line 68, in execute
return self._execute_with_wrappers(sql, params, many=False, executor=self._execute)
File "/home/ubuntu/myapp-env/lib/python3.5/site-packages/django/db/backends/utils.py", line 77, in _execute_with_wrappers
return executor(sql, params, many, context)
File "/home/ubuntu/myapp-env/lib/python3.5/site-packages/django/db/backends/utils.py", line 85, in _execute
return self.cursor.execute(sql, params)
File "/home/ubuntu/myapp-env/lib/python3.5/site-packages/django/db/utils.py", line 89, in __exit__
raise dj_exc_value.with_traceback(traceback) from exc_value
File "/home/ubuntu/myapp-env/lib/python3.5/site-packages/django/db/backends/utils.py", line 85, in _execute
return self.cursor.execute(sql, params)
File "/home/ubuntu/myapp-env/lib/python3.5/site-packages/django/db/backends/mysql/base.py", line 71, in execute
return self.cursor.execute(query, args)
File "/home/ubuntu/myapp-env/lib/python3.5/site-packages/pymysql/cursors.py", line 165, in execute
result = self._query(query)
File "/home/ubuntu/myapp-env/lib/python3.5/site-packages/pymysql/cursors.py", line 321, in _query
conn.query(q)
File "/home/ubuntu/myapp-env/lib/python3.5/site-packages/pymysql/connections.py", line 860, in query
self._affected_rows = self._read_query_result(unbuffered=unbuffered)
File "/home/ubuntu/myapp-env/lib/python3.5/site-packages/pymysql/connections.py", line 1061, in _read_query_result
result.read()
File "/home/ubuntu/myapp-env/lib/python3.5/site-packages/pymysql/connections.py", line 1349, in read
first_packet = self.connection._read_packet()
File "/home/ubuntu/myapp-env/lib/python3.5/site-packages/pymysql/connections.py", line 1018, in _read_packet
packet.check_error()
File "/home/ubuntu/myapp-env/lib/python3.5/site-packages/pymysql/connections.py", line 384, in check_error
err.raise_mysql_exception(self._data)
File "/home/ubuntu/myapp-env/lib/python3.5/site-packages/pymysql/err.py", line 107, in raise_mysql_exception
raise errorclass(errno, errval)
django.db.utils.InternalError: (1364, "Field 'name' doesn't have a default value")

現在の評価: 2
タイトルとURLをコピー

コメント

アーカイブ

2024
2023
2022
2021
2020
2019
2018
2017
2016
2015
2014
2013
2012
2011