23
votes

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'
4
A complete traceback would help a lot. Also which Django 1.7 version have you installed? (e.g. 1.7.1)alecxe
Just edited with the complete traceback. Not sure about the specific version of 1.7...I just did a pip install django==1.7Denny

4 Answers

42
votes

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 --upgrade python manage.py migrate

7
votes

Had the same problem. I solved it with:

pip install django --upgrade

python manage.py makemigrations

python manage.py migrate

Why exactly it gets solved like that, I dont know, someone with deeper knowledge might be able to explain...

1
votes
pip install "django<1.8" -U

then run migrations.... If you update without versioning you'll end up with another active trunk and it's not what you want.

0
votes

I met the same problem. and I found my Django version is 1.7.0. After running pip install django --upgrade, my Django version changed to 1.7.4, and the problem is gone.

I remember the other computer that sync the projects files with this one through Internet, has Django version 1.7.3. So I come to the conclusion that this problem is caused by inconsistent versions of Django.