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 --upgrade
python manage.py migrate
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...
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.
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.
Related
I was trying to run a Django project which I got from someone else.
But I can't do the migration.
I came from a mobile app development background. So I'm quite new to this backend thing including Django.
Please have a look and help with this issue. Thank you
Traceback (most recent call last):
File "/Users/punreachrany/Desktop/MyProject/manage.py", line 22, in <module>
main()
File "/Users/punreachrany/Desktop/MyProject/manage.py", line 18, in main
execute_from_command_line(sys.argv)
File "/Users/punreachrany/opt/anaconda3/lib/python3.9/site-packages/django/core/management/__init__.py", line 446, in execute_from_command_line
utility.execute()
File "/Users/punreachrany/opt/anaconda3/lib/python3.9/site-packages/django/core/management/__init__.py", line 420, in execute
django.setup()
File "/Users/punreachrany/opt/anaconda3/lib/python3.9/site-packages/django/__init__.py", line 24, in setup
apps.populate(settings.INSTALLED_APPS)
File "/Users/punreachrany/opt/anaconda3/lib/python3.9/site-packages/django/apps/registry.py", line 91, in populate
app_config = AppConfig.create(entry)
File "/Users/punreachrany/opt/anaconda3/lib/python3.9/site-packages/django/apps/config.py", line 228, in create
import_module(entry)
File "/Users/punreachrany/opt/anaconda3/lib/python3.9/importlib/__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1030, in _gcd_import
File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
File "<frozen importlib._bootstrap>", line 984, in _find_and_load_unlocked
ModuleNotFoundError: No module named 'bootstrap4'
Bootstrap is a dependency you need to add. You can install it by running the below command before migrating.(This is a one time setup)
python -m pip install bootstrap4
Since you mentioned you got the project from someone else.In that case check if there is a file called requirements.txt.
If it exists, run the below command from that directory to install all the required dependencies.
Python -m pip install -r requirements.txt
So, im new to Django and for the sake of learning im trying to get a project up with allauth while extending AbstractBaseUser.
The project starts, there is no problem there, the login screen from allauth displays my custom model (login with email). But when i try to create a superuser i get the following error.
Traceback (most recent call last):
File "manage.py", line 21, in <module>
main()
File "manage.py", line 17, in main
execute_from_command_line(sys.argv)
File "C:\users\bramv\appdata\local\programs\python\python38\lib\site-packages\django\core\management\__init__.py", line 401, in execute_from_command_line
utility.execute()
File "C:\users\bramv\appdata\local\programs\python\python38\lib\site-packages\django\core\management\__init__.py", line 377, in execute
django.setup()
File "C:\users\bramv\appdata\local\programs\python\python38\lib\site-packages\django\__init__.py", line 24, in setup
apps.populate(settings.INSTALLED_APPS)
File "C:\users\bramv\appdata\local\programs\python\python38\lib\site-packages\django\apps\registry.py", line 91, in populate
app_config = AppConfig.create(entry)
File "C:\users\bramv\appdata\local\programs\python\python38\lib\site-packages\django\apps\config.py", line 90, in create
module = import_module(entry)
File "C:\users\bramv\appdata\local\programs\python\python38\lib\importlib\__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1014, in _gcd_import
File "<frozen importlib._bootstrap>", line 991, in _find_and_load
File "<frozen importlib._bootstrap>", line 973, in _find_and_load_unlocked
ModuleNotFoundError: No module named 'allauth'
I did setup a virtualenv and installed django-allauth with pip and i followed the install instructions from the django-allauth docs. I fail to see where this error is comming from, any help would be greatly appreciated.
Install the library first. In your console:
pip install django-allauth
I'm adding django-celery to my project, there's currently an issue you'll experience where a first install of this installs an outdated celery which you need to update and it has a dependency django-celery-results which also has it's expected version for each depending on it's version.
I've ended up with the following versions
Name: django-celery-results
Version: 1.0.0
Name: django-celery
Version: 3.3.1
Name: celery
Version: 4.4.0
in my app/tasks.py I have the following code
from celery import shared_task
from django.conf import settings
#shared_task
def update_extend():
users = User.objects.filter(is_active=True)
for user in users:
....
based on the docs this seems like the next line of code to test
(fortnox) sam#sam:/media/veracrypt1/fortnox$ python manage.py celery
Traceback (most recent call last):
File "manage.py", line 21, in <module>
main()
File "manage.py", line 17, in main
execute_from_command_line(sys.argv)
File "/home/sam/code/envs/fortnox/lib/python3.6/site-packages/django/core/management/__init__.py", line 401, in execute_from_command_line
utility.execute()
File "/home/sam/code/envs/fortnox/lib/python3.6/site-packages/django/core/management/__init__.py", line 395, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/home/sam/code/envs/fortnox/lib/python3.6/site-packages/django/core/management/__init__.py", line 244, in fetch_command
klass = load_command_class(app_name, subcommand)
File "/home/sam/code/envs/fortnox/lib/python3.6/site-packages/django/core/management/__init__.py", line 37, in load_command_class
module = import_module('%s.management.commands.%s' % (app_name, name))
File "/home/sam/code/envs/fortnox/lib/python3.6/importlib/__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 994, in _gcd_import
File "<frozen importlib._bootstrap>", line 971, in _find_and_load
File "<frozen importlib._bootstrap>", line 955, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 665, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 678, in exec_module
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "/home/sam/code/envs/fortnox/lib/python3.6/site-packages/djcelery/management/commands/celery.py", line 11, in <module>
class Command(CeleryCommand):
File "/home/sam/code/envs/fortnox/lib/python3.6/site-packages/djcelery/management/commands/celery.py", line 16, in Command
tuple(base.get_options()) +
TypeError: 'NoneType' object is not iterable
which throws the error shown above.
django-celery does not support Django versions higher than Django 1.10.* also does not support celery 4.*.*
From Celery documentation for Django
Previous versions of Celery required a separate library to work with
Django, but since 3.1 this is no longer the case. Django is supported
out of the box now so this document only contains a basic way to
integrate Celery and Django. You’ll use the same API as non-Django
users so you’re recommended to read the First Steps with Celery
tutorial first and come back to this tutorial. When you have a working
example you can continue to the Next Steps guide.
You can still use django-celery-results but withouth needs of djcelery
Can someone provide more details on setting up and utilizing django_pg. I would like to use the array functionality.
By following the setup of two simple steps from here:
https://django-pgfields.readthedocs.io/en/latest/usage.html
Results in this error:
(environment) jeff#jeff-computer:~/environment/projectA$ python manage.py makemigrations
Traceback (most recent call last):
File "manage.py", line 15, in <module>
execute_from_command_line(sys.argv)
File "/home/jeff/environment/lib/python3.7/site-packages/django/core/management/__init__.py", line 381, in execute_from_command_line
utility.execute()
File "/home/jeff/environment/lib/python3.7/site-packages/django/core/management/__init__.py", line 357, in execute
django.setup()
File "/home/jeff/environment/lib/python3.7/site-packages/django/__init__.py", line 24, in setup
apps.populate(settings.INSTALLED_APPS)
File "/home/jeff/environment/lib/python3.7/site-packages/django/apps/registry.py", line 89, in populate
app_config = AppConfig.create(entry)
File "/home/jeff/environment/lib/python3.7/site-packages/django/apps/config.py", line 90, in create
module = import_module(entry)
File "/home/jeff/miniconda3/lib/python3.7/importlib/__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1006, in _gcd_import
File "<frozen importlib._bootstrap>", line 983, in _find_and_load
File "<frozen importlib._bootstrap>", line 965, in _find_and_load_unlocked
ModuleNotFoundError: No module named 'django_pg'
It looks like you forgot to do pip install django-pgfields to install it.
However, you probably shouldn’t be using this package. It hasn’t had any updates for years, so won’t support modern versions of Django.
Since Django 1.8,
Django comes with django.contrib.postgres, which might provide the Postgres functionality that you require.
I tried several times now to deploy my Heroku application but I always receive the attached error message. After adding DISABLE_COLLECTSTATIC=1 it works and I can remove it after. But it never works when it's enabled which it should be. Here a picture of my folder structure if it's needed https://drive.google.com/file/d/11L8jpFzYfDYT3Ob4G-soaGhL0pgU24iZ/view?usp=sharing
! Warning: Multiple default buildpacks reported the ability to handle this app. The first buildpack in the list below will be used.
Detected buildpacks: Python,Node.js
See https://devcenter.heroku.com/articles/buildpacks#buildpack-detect-order
-----> Python app detected
-----> Installing python-3.6.6
-----> Installing pip
-----> Installing dependencies with Pipenv 2018.5.18…
Installing dependencies from Pipfile.lock (d438cb)…
-----> Installing SQLite3
-----> $ python manage.py collectstatic --noinput
Traceback (most recent call last):
File "manage.py", line 15, in <module>
execute_from_command_line(sys.argv)
File "/app/.heroku/python/lib/python3.6/site-packages/django/core/management/__init__.py", line 371, in execute_from_command_line
utility.execute()
File "/app/.heroku/python/lib/python3.6/site-packages/django/core/management/__init__.py", line 347, in execute
django.setup()
File "/app/.heroku/python/lib/python3.6/site-packages/django/__init__.py", line 24, in setup
apps.populate(settings.INSTALLED_APPS)
File "/app/.heroku/python/lib/python3.6/site-packages/django/apps/registry.py", line 112, in populate
app_config.import_models()
File "/app/.heroku/python/lib/python3.6/site-packages/django/apps/config.py", line 198, in import_models
self.models_module = import_module(models_module_name)
File "/app/.heroku/python/lib/python3.6/importlib/__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 994, in _gcd_import
File "<frozen importlib._bootstrap>", line 971, in _find_and_load
File "<frozen importlib._bootstrap>", line 955, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 665, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 678, in exec_module
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "/app/.heroku/python/lib/python3.6/site-packages/django/contrib/auth/models.py", line 2, in <module>
from django.contrib.auth.base_user import AbstractBaseUser, BaseUserManager
File "/app/.heroku/python/lib/python3.6/site-packages/django/contrib/auth/base_user.py", line 47, in <module>
class AbstractBaseUser(models.Model):
File "/app/.heroku/python/lib/python3.6/site-packages/django/db/models/base.py", line 114, in __new__
new_class.add_to_class('_meta', Options(meta, app_label))
File "/app/.heroku/python/lib/python3.6/site-packages/django/db/models/base.py", line 315, in add_to_class
value.contribute_to_class(cls, name)
File "/app/.heroku/python/lib/python3.6/site-packages/django/db/models/options.py", line 205, in contribute_to_class
self.db_table = truncate_name(self.db_table, connection.ops.max_name_length())
File "/app/.heroku/python/lib/python3.6/site-packages/django/db/__init__.py", line 33, in __getattr__
return getattr(connections[DEFAULT_DB_ALIAS], item)
File "/app/.heroku/python/lib/python3.6/site-packages/django/db/utils.py", line 199, in __getitem__
self.ensure_defaults(alias)
File "/app/.heroku/python/lib/python3.6/site-packages/django/db/utils.py", line 171, in ensure_defaults
conn.setdefault('ATOMIC_REQUESTS', False)
AttributeError: 'NoneType' object has no attribute 'setdefault'
! Error while running '$ python manage.py collectstatic --noinput'.
See traceback above for details.
You may need to update application code to resolve this error.
Or, you can disable collectstatic for this application:
$ heroku config:set DISABLE_COLLECTSTATIC=1
https://devcenter.heroku.com/articles/django-assets
! Push rejected, failed to compile Python app.
! Push failed
It might be unrelated to collectstatic. Similar exception was described here: python error AttributeError: 'str' object has no attribute 'setdefault'.
I'd suggest checking your DATABASES setting in your settings.py. Check out django-heroku (https://github.com/heroku/django-heroku) if you're not using it already and just use this in your settings:
import django_heroku
django_heroku.settings(locals())