本文介绍了Django 1.7迁移的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用django 1.7,我刚刚添加了一个自定义用户模型。当我运行 python3 manage.py makemigrations
或 python3 manage.py migrate
我得到错误: TypeError:__init __()得到了一个意想不到的关键字参数preserve_default
。添加新的自定义用户模型后出现此问题。完整的追溯是: 追溯(最近的最后一次呼叫):
文件manage.py,第10行,< module>
execute_from_command_line(sys.argv)
文件/usr/local/lib/python3.4/dist-packages/django/core/management/__init__.py,第385行,execute_from_command_line
utility.execute()
文件/usr/local/lib/python3.4/dist-packages/django/core/management/__init__.py,第377行,执行
self.fetch_command (子命令).run_from_argv(self.argv)
文件/usr/local/lib/python3.4/dist-packages/django/core/management/base.py,第288行,在run_from_argv
self.execute(* args,** options .__ dict__)
文件/usr/local/lib/python3.4/dist-packages/django/core/management/base.py,第338行,执行
output = self.handle(* args,** options)
文件/usr/local/lib/python3.4/dist-packages/django/core/management/commands/migrate.py ,第63行,在句柄
executor = MigrationExecutor(connection,self.migration_progress_callback)
文件/usr/local/lib/python3.4/dist-packages/django/db/migrations/executor。 py,第17行,__init__
self.loader = MigrationLoader(self.connection)
文件/usr/local/lib/python3.4/dist-packages/django/db/migrations/loader.py,第48行,__init__
self.build_graph()
文件/usr/local/lib/python3.4/dist-packages/django/db/migrations/loader.py,第173行,build_graph
自身.load_disk()
文件/usr/local/lib/python3.4/dist-packages/django/db/migrations/loader.py,第103行,在load_disk
migration_module = import_module( %s。%s%(module_name,migration_name))
文件/usr/lib/python3.4/importlib/__init__.py,第109行,import_module
return _bootstrap._gcd_import(name [level:],package,level)
文件< frozen importlib._bootstrap>,第2231行,_gcd_import
文件< frozen importlib._bootstrap>,第2214行,_find_and_load
文件< frozen importlib._bootstrap>,第2203行,_find_and_load_unlocked
文件< frozen importlib._bootstrap>,第1200行,_load_unlocked
文件< frozen importlib._bootstrap>,第1129行,在_exec
文件< frozen importlib._bootstrap>,行1448,在exec_module
文件< frozen importlib._bootstrap第321行,在_call_with_frames_removed
文件/home/denny/workspace/teenvestor/core/migrations/0003_auto_20141017_1749.py中,第7行在< module>
class Migration(migrations.Migration):
文件/home/denny/workspace/teenvestor/core/migrations/0003_auto_20141017_1749.py,第46行,Migration
preserve_default = True,
TypeError:__init __()得到一个意想不到的关键字参数'preserve_default'
解决方案
Django 1.7.1在AlterField中添加了对preserve_default参数的支持。因此,从1.7版本升级Django将解决问题。
pip install django --upgrade
python manage.py migrate
I am using django 1.7 and I just added a custom user model. When I run either python3 manage.py makemigrations
or python3 manage.py migrate
I get the error: TypeError: __init__() got an unexpected keyword argument 'preserve_default'
. This issue came along after adding the new custom user model. The complete traceback is:
Traceback (most recent call last):
File "manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "/usr/local/lib/python3.4/dist-packages/django/core/management/__init__.py", line 385, in execute_from_command_line
utility.execute()
File "/usr/local/lib/python3.4/dist-packages/django/core/management/__init__.py", line 377, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/usr/local/lib/python3.4/dist-packages/django/core/management/base.py", line 288, in run_from_argv
self.execute(*args, **options.__dict__)
File "/usr/local/lib/python3.4/dist-packages/django/core/management/base.py", line 338, in execute
output = self.handle(*args, **options)
File "/usr/local/lib/python3.4/dist-packages/django/core/management/commands/migrate.py", line 63, in handle
executor = MigrationExecutor(connection, self.migration_progress_callback)
File "/usr/local/lib/python3.4/dist-packages/django/db/migrations/executor.py", line 17, in __init__
self.loader = MigrationLoader(self.connection)
File "/usr/local/lib/python3.4/dist-packages/django/db/migrations/loader.py", line 48, in __init__
self.build_graph()
File "/usr/local/lib/python3.4/dist-packages/django/db/migrations/loader.py", line 173, in build_graph
self.load_disk()
File "/usr/local/lib/python3.4/dist-packages/django/db/migrations/loader.py", line 103, in load_disk
migration_module = import_module("%s.%s" % (module_name, migration_name))
File "/usr/lib/python3.4/importlib/__init__.py", line 109, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 2231, in _gcd_import
File "<frozen importlib._bootstrap>", line 2214, in _find_and_load
File "<frozen importlib._bootstrap>", line 2203, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 1200, in _load_unlocked
File "<frozen importlib._bootstrap>", line 1129, in _exec
File "<frozen importlib._bootstrap>", line 1448, in exec_module
File "<frozen importlib._bootstrap>", line 321, in _call_with_frames_removed
File "/home/denny/workspace/teenvestor/core/migrations/0003_auto_20141017_1749.py", line 7, in <module>
class Migration(migrations.Migration):
File "/home/denny/workspace/teenvestor/core/migrations/0003_auto_20141017_1749.py", line 46, in Migration
preserve_default=True,
TypeError: __init__() got an unexpected keyword argument 'preserve_default'
解决方案
Django 1.7.1 added support for the preserve_default param in AlterField. Therefore an upgrade of Django from version 1.7 will resolve the issue.
pip install django --upgradepython manage.py migrate
这篇关于Django 1.7迁移的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
09-06 15:29