How to use ArrayField in Django using PostgreSQL DB? - django

I want to do this import in my django models.py:
from django.contrib.postgres.fields import ArrayField
I read this documentation https://docs.djangoproject.com/en/dev/ref/contrib/ and I added
'django.contrib.postgres' into my INSTALLED_APPS in settings.py, but when I try to sync my db or to runserver I got "ImportError: No module named postgres"
Is there something else I should do or install? django.contrib.postgres is part of the core distribution right?
This is traceback:
Traceback (most recent call last):
File "manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "c:\Python27\lib\site-packages\django\core\management\__init__.py", line 399, in execute_from_com
utility.execute()
File "c:\Python27\lib\site-packages\django\core\management\__init__.py", line 392, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "c:\Python27\lib\site-packages\django\core\management\base.py", line 242, in run_from_argv
self.execute(*args, **options.__dict__)
File "c:\Python27\lib\site-packages\django\core\management\base.py", line 280, in execute
translation.activate('en-us')
File "c:\Python27\lib\site-packages\django\utils\translation\__init__.py", line 130, in activate
return _trans.activate(language)
File "c:\Python27\lib\site-packages\django\utils\translation\trans_real.py", line 188, in activate
_active.value = translation(language)
File "c:\Python27\lib\site-packages\django\utils\translation\trans_real.py", line 177, in translation
default_translation = _fetch(settings.LANGUAGE_CODE)
File "c:\Python27\lib\site-packages\django\utils\translation\trans_real.py", line 159, in _fetch
app = import_module(appname)
File "c:\Python27\lib\site-packages\django\utils\importlib.py", line 40, in import_module
__import__(name)
ImportError: No module named postgres

django.contrib.postgres will be a part of 1.8 release.

Fortunately there are several unofficial implementations postgresql arrays in django. One of the most notable being djorm-pgarray. Another option is django-dbarray when Django 1.8 eventually gets rolled out, migration shouldn't be too difficult.

Related

Migration urls in app ...has no Migration class

When I try to run migration I get "Migration urls in app *** has no Migration class"? I just added new app.
Have no idea what direction to look. Traceback:
C:\Users\PAPA\DEV\liberty\lib\site-packages\django\db\models\__init__.py:55:
RemovedInDjango19Warning: The utilities in django.db.models.loading are deprecated
in favor of the new application loading system.
from . import loading
Traceback (most recent call last): File "manage.py", line 22, in <module>
execute_from_command_line(sys.argv)
File "...\django\core\management\__init__.py", line 338, in execute_from_command_line
utility.execute()
File "...\django\core\management\__init__.py", line 330, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "...\django\core\management\base.py", line 390, in run_from_argv
self.execute(*args, **cmd_options)
File "...\django\core\management\base.py", line 441, in execute
output = self.handle(*args, **options)
File "...\django\core\management\commands\makemigrations.py", line 63, in handle
loader = MigrationLoader(None, ignore_no_migrations=True)
File "...\django\db\migrations\loader.py", line 47, in __init__
self.build_graph()
File "...\django\db\migrations\loader.py", line 174, in build_graph
self.load_disk()
File "...\django\db\migrations\loader.py", line 109, in load_disk
"Migration %s in app %s has no Migration class" % (migration_name, app_config.label)
django.db.migrations.loader.BadMigrationError: Migration urls in app expense has no
Migration class
That exception
BadMigrationError: "Migration *** in app *** has no Migration class"
is raised if the "migrations/" directory of the application contains a file that is not a valid migration file.
In your case it is a file "urls.py" in migrations of the application "expense".

django-admin --version error

I was working on a Django project and I ran to the error below please help.
I tried to check my django version with the " django-admin --version " command and i ran into this error below.
Traceback (most recent call last):
File "/usr/local/bin/django-admin", line 11, in <module>
sys.exit(execute_from_command_line())
File "/usr/local/lib/python2.7/dist-packages/django/core/management/__init__.py", line 354, in execute_from_command_line
utility.execute()
File "/usr/local/lib/python2.7/dist-packages/django/core/management/__init__.py", line 328, in execute
django.setup()
File "/usr/local/lib/python2.7/dist-packages/django/__init__.py", line 18, in setup
apps.populate(settings.INSTALLED_APPS)
File "/usr/local/lib/python2.7/dist-packages/django/apps/registry.py", line 85, in populate
app_config = AppConfig.create(entry)
File "/usr/local/lib/python2.7/dist-packages/django/apps/config.py", line 86, in create
module = import_module(entry)
File "/usr/lib/python2.7/importlib/__init__.py", line 37, in import_module
__import__(name)
ImportError: No module named south
You have include south in your INSTALLED_APPS settings, but it is not installed.
From the traceback, it looks as if you are using Django 1.7 or later, so South is no longer required. You should remove it from INSTALLED_APPS in your settings.

Django unable to migrate database on Heroku

I try to deploy app on Heroku but after running command 'heroku run python manage.py migrate' I get an error:
Running `python manage.py migrate` attached to terminal... up, run.5928
Traceback (most recent call last):
File "manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "/app/.heroku/python/lib/python2.7/site-packages/django/core/management/__init__.py", line 385, in execute_from_command_line
utility.execute()
File "/app/.heroku/python/lib/python2.7/site-packages/django/core/management/__init__.py", line 377, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/app/.heroku/python/lib/python2.7/site-packages/django/core/management/base.py", line 288, in run_from_argv
self.execute(*args, **options.__dict__)
File "/app/.heroku/python/lib/python2.7/site-packages/django/core/management/base.py", line 338, in execute
output = self.handle(*args, **options)
File "/app/.heroku/python/lib/python2.7/site-packages/django/core/management/commands/migrate.py", line 63, in handle
executor = MigrationExecutor(connection, self.migration_progress_callback)
File "/app/.heroku/python/lib/python2.7/site-packages/django/db/migrations/executor.py", line 17, in __init__
self.loader = MigrationLoader(self.connection)
File "/app/.heroku/python/lib/python2.7/site-packages/django/db/migrations/loader.py", line 48, in __init__
self.build_graph()
File "/app/.heroku/python/lib/python2.7/site-packages/django/db/migrations/loader.py", line 173, in build_graph
self.load_disk()
File "/app/.heroku/python/lib/python2.7/site-packages/django/db/migrations/loader.py", line 103, in load_disk
migration_module = import_module("%s.%s" % (module_name, migration_name))
File "/app/.heroku/python/lib/python2.7/importlib/__init__.py", line 37, in import_module
__import__(name)
File "/app/joins/migrations/0004_auto_20150211_1924.py", line 7, in <module>
class Migration(migrations.Migration):
File "/app/joins/migrations/0004_auto_20150211_1924.py", line 18, in Migration
preserve_default=True,
TypeError: __init__() got an unexpected keyword argument 'preserve_default'
Do you have any suggestion?
You can try to see this :
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
From : Django 1.7 Migrations
.

django1.4.0:ImportError: No module named base

Now I have a problem as the title. Here is my environment:
OS:ubuntu 10.10
Python:2.6.6
Django:1.4 pre-alpha
Before, I installed Django 1.1.1 for the The Django Book. Today , I removed Django 1.1.1 by cmd: sudo apt-get install --purge python-django, then get the latest version of 1.4 pre-alpha.
when I followed the tutorial on the docs.djangoproject.com, and execute cmd: python manage.py shell, it comes some error and the infomation like this:
Traceback (most recent call last):
File "manage.py", line 9, in <module>
execute_from_command_line(sys.argv)
File "/usr/local/lib/python2.6/dist-packages/django/core/management/__init__.py", line 422, in execute_from_command_line
utility.execute()
File "/usr/local/lib/python2.6/dist-packages/django/core/management/__init__.py", line 361, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/usr/local/lib/python2.6/dist-packages/django/core/management/base.py", line 191, in run_from_argv
self.execute(*args, **options.__dict__)
File "/usr/local/lib/python2.6/dist-packages/django/core/management/base.py", line 222, in execute
output = self.handle(*args, **options)
File "/usr/local/lib/python2.6/dist-packages/django/core/management/base.py", line 355, in handle
return self.handle_noargs(**options)
File "/usr/local/lib/python2.6/dist-packages/django/core/management/commands/shell.py", line 46, in handle_noargs
from django.db.models.loading import get_models
File "/usr/local/lib/python2.6/dist-packages/django/db/__init__.py", line 27, in <module>
connection = connections[DEFAULT_DB_ALIAS]
File "/usr/local/lib/python2.6/dist-packages/django/db/utils.py", line 81, in __getitem__
backend = load_backend(db['ENGINE'])
File "/usr/local/lib/python2.6/dist-packages/django/db/utils.py", line 23, in load_backend
return import_module('.base', backend_name)
File "/usr/local/lib/python2.6/dist-packages/django/utils/importlib.py", line 35, in import_module
__import__(name)
ImportError: No module named base
Could some guys tell me how solve this problem?
Thanks!!
The problem is probably because You have no full path for your DB backend. You probably have:
'ENGINE': 'sqlite3',
instead of:
'ENGINE': 'django.db.backends.sqlite3',
You must call manage.py from the folder where settings.py is located: ../manage.py shell
(In case using sqlite3)
(And djando 1.4)

Django MongoDB problem

my django app run with mysql, but when i try with mongodb then show thie error
Traceback (most recent call last):
File "manage.py", line 14, in <module>
execute_manager(settings)
File "/home/abdullah/django-trunk/django/core/management/__init__.py", line 442, in execute_manager
utility.execute()
File "/home/abdullah/django-trunk/django/core/management/__init__.py", line 379, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/home/abdullah/django-trunk/django/core/management/base.py", line 191, in run_from_argv
self.execute(*args, **options.__dict__)
File "/home/abdullah/django-trunk/django/core/management/base.py", line 209, in execute
translation.activate('en-us')
File "/home/abdullah/django-trunk/django/utils/translation/__init__.py", line 106, in activate
return _trans.activate(language)
File "/home/abdullah/django-trunk/django/utils/translation/trans_real.py", line 191, in activate
_active.value = translation(language)
File "/home/abdullah/django-trunk/django/utils/translation/trans_real.py", line 180, in translation
default_translation = _fetch(settings.LANGUAGE_CODE)
File "/home/abdullah/django-trunk/django/utils/translation/trans_real.py", line 157, in _fetch
app = import_module(appname)
File "/home/abdullah/django-trunk/django/utils/importlib.py", line 35, in import_module
__import__(name)
File "/home/abdullah/django-trunk/django/contrib/admin/__init__.py", line 3, in <module>
from django.contrib.admin.helpers import ACTION_CHECKBOX_NAME
File "/home/abdullah/django-trunk/django/contrib/admin/helpers.py", line 2, in <module>
from django.contrib.admin.util import (flatten_fieldsets, lookup_field,
File "/home/abdullah/django-trunk/django/contrib/admin/util.py", line 1, in <module>
from django.db import models
File "/home/abdullah/django-trunk/django/db/__init__.py", line 27, in <module>
connection = connections[DEFAULT_DB_ALIAS]
File "/home/abdullah/django-trunk/django/db/utils.py", line 82, in __getitem__
conn = backend.DatabaseWrapper(db, alias)
File "/usr/local/lib/python2.6/dist-packages/django_mongodb_engine-0.4.0-py2.6.egg/django_mongodb_engine/base.py", line 87, in __init__
self.ops = DatabaseOperations(self)
File "/usr/local/lib/python2.6/dist-packages/djangotoolbox-0.9.2-py2.6.egg/djangotoolbox/db/base.py", line 28, in __init__
super(NonrelDatabaseOperations, self).__init__()
TypeError: __init__() takes exactly 2 arguments (1 given)
** I have installed all necessary module installed, but when i want to runserver then show this message
I managed to fix the same error by using these packages on github:
https://github.com/django-nonrel/django-nonrel
https://github.com/django-nonrel/djangotoolbox
instead of the ones recommended on Django-Mongodb's setup page. Also, make sure to use the master branch of each, so as to not run into compatibility problems. If you're using pip, you can either pip install each of the following lines separately, or put them into your version of a requirements.txt file for your project:
git+https://github.com/django-nonrel/django-nonrel#master
git+https://github.com/django-nonrel/djangotoolbox#master
git+https://github.com/django-nonrel/mongodb-engine#master
And then run
pip install -r requirements.txt