Cannot run migrate while using an existing database - django

I am using Django3 and Python3 with the latest version to learn Django.
I want to use an existing sqlite3 database for my django project. But I have problems while I was using the migrate command.
I have done very few steps to my project so far:
1. use the venv, upgrade pip, install django,
2. generate a project,
3. insert an app, and add it into INSTALLED_APPS,
4. In the settings.py, I added the existing database into the DATABASES as follows.
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
},
'testdb': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': os.path.join(BASE_DIR, 'TestDB.sqlite3'),
},
}
Then I use the method as here shows, to generate the models.py file.
Using existing database in Django
The generated models.py looks like: (where I added the max_length=25)
from django.db import models
class Stars(models.Model):
actorname = models.CharField(db_column='ActorName', blank=True, null=True, max_length=25)
realname = models.CharField(db_column='RealName', blank=True, null=True, max_length=25)
class Meta:
managed = False
db_table = 'Stars'
6. Then I run python manage.py migrate and/or python manage.py makemigrations, here I see the following errors:
(venv) PS D:\Workfolder_Web\testProject\backend\project> python .\manage.py migrate
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 "D:\Workfolder_Web\testProject\backend\venv\lib\site-packages\django\core\management\__init__.py", line 401, in execute_from_command_line
utility.execute()
File "D:\Workfolder_Web\testProject\backend\venv\lib\site-packages\django\core\management\__init__.py", line 377, in execute
django.setup()
File "D:\Workfolder_Web\testProject\backend\venv\lib\site-packages\django\__init__.py", line 24, in setup
apps.populate(settings.INSTALLED_APPS)
File "D:\Workfolder_Web\testProject\backend\venv\lib\site-packages\django\apps\registry.py", line 114, in populate
app_config.import_models()
File "D:\Workfolder_Web\testProject\backend\venv\lib\site-packages\django\apps\config.py", line 211, in import_models
self.models_module = import_module(models_module_name)
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python38-32\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 975, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 671, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 779, in exec_module
File "<frozen importlib._bootstrap_external>", line 916, in get_code
File "<frozen importlib._bootstrap_external>", line 846, in source_to_code
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
ValueError: source code string cannot contain null bytes
7. My database TestDB.sqlite3 is very simple, it looks like:
Question: How could I debug it? I am not using any bootstrap, urls, views or routers in my current codes.
Thanks for the help!

If you changed the Models you either add a default value for the new fields or remove the database.

Related

How to access a Django model outside a Django project?

The problem below is raised after reviewing all the related SO questions, but unfortunately none of the answers brought a solution in my case (similar problem like: How to access Django models outside of Django?).
(with Django version: 4.1.1)
Having an application "simo" available with the related model, the db access works well from Django shell; but trying to access to it from outside Django as "scheduling.py", it just does not work.
import os
import django
os.environ['DJANGO_SETTINGS_MODULE'] = 'mysite.settings'
django.setup()
from django.db import models
from simo.models import Tasks
I tried to execute my python script in any folder:
beside manage.py,
beside settings.py and
beside models.py but none of them works.
[mysite]
[mysite]
[simo]
[migrations]
views.py
models.py
urls.py
__init__.py
apps.py
tests.py
admin.py
settings.py
urls.py
__init__.py
wsgi.py
asgi.py
scheduling.py
__init__.py
db.sqlite3
manage.py
The error received is:
C:\...\python.exe C:/.../mysite/scheduling.py
Traceback (most recent call last):
File "C:\...\mysite\scheduling.py", line 5, in <module>
django.setup()
File "C:\...\lib\site-packages\django\__init__.py", line 24, in setup
apps.populate(settings.INSTALLED_APPS)
File "C:\...\lib\site-packages\django\apps\registry.py", line 91, in populate
app_config = AppConfig.create(entry)
File "C:\...\lib\site-packages\django\apps\config.py", line 178, in create
mod = import_module(mod_path)
File "C:\...\lib\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 972, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 228, in _call_with_frames_removed
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 'simo'
Process finished with exit code 1
Could anyone advise me on how to resolve this issue?
Try calling
from django.db import models and from simo.models import Tasks before django.setup()

django 2.1.3 'django.db.backends.postgis' isn't an available database backend

I am trying to use geodjango for a project. Before I use geodjango I'm trying to do a learn it from the following tutorial: https://docs.djangoproject.com/en/2.1/ref/contrib/gis/tutorial/
I originally had django 1.11 installed and tried following that tutorial (stupid of me). However, after uninstalling django 1.11 and installing django 2.1.3 I am encountering some errors.
After I make the model according to the tutorial, I use the command
python3 manage.py makemigrations
I end up getting the following error:
Traceback (most recent call last):
File "/home/aihoque2/.local/lib/python3.6/site- packages/django/db/utils.py", line 110, in load_backend
return import_module('%s.base' % backend_name)
File "/usr/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 941, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "<frozen importlib._bootstrap>", line 994, in _gcd_import
File "<frozen importlib._bootstrap>", line 971, in _find_and_load
File "<frozen importlib._bootstrap>", line 953, in _find_and_load_unlocked
ModuleNotFoundError: No module named 'django.db.backends.postgis'
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "manage.py", line 15, in <module>
execute_from_command_line(sys.argv)
File "/home/aihoque2/.local/lib/python3.6/site-packages/django/core/management/__init__.py", line 381, in execute_from_command_line
utility.execute()
File "/home/aihoque2/.local/lib/python3.6/site-packages/django/core/management/__init__.py", line 357, in execute
django.setup()
File "/home/aihoque2/.local/lib/python3.6/site-packages/django/__init__.py", line 24, in setup
apps.populate(settings.INSTALLED_APPS)
File "/home/aihoque2/.local/lib/python3.6/site-packages/django/apps/registry.py", line 112, in populate
app_config.import_models()
File "/home/aihoque2/.local/lib/python3.6/site-packages/django/apps/config.py", line 198, in import_models
self.models_module = import_module(models_module_name)
File "/usr/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/aihoque2/.local/lib/python3.6/site-packages/django/contrib/auth/models.py", line 2, in <module>
from django.contrib.auth.base_user import AbstractBaseUser, BaseUserManager
File "/home/aihoque2/.local/lib/python3.6/site-packages/django/contrib/auth/base_user.py", line 47, in <module>
class AbstractBaseUser(models.Model):
File "/home/aihoque2/.local/lib/python3.6/site-packages/django/db/models/base.py", line 101, in __new__
new_class.add_to_class('_meta', Options(meta, app_label))
File "/home/aihoque2/.local/lib/python3.6/site-packages/django/db/models/base.py", line 305, in add_to_class
value.contribute_to_class(cls, name)
File "/home/aihoque2/.local/lib/python3.6/site-packages/django/db/models/options.py", line 203, in contribute_to_class
self.db_table = truncate_name(self.db_table, connection.ops.max_name_length())
File "/home/aihoque2/.local/lib/python3.6/site-packages/django/db/__init__.py", line 33, in __getattr__
return getattr(connections[DEFAULT_DB_ALIAS], item)
File "/home/aihoque2/.local/lib/python3.6/site-packages/django/db/utils.py", line 202, in __getitem__
backend = load_backend(db['ENGINE'])
File "/home/aihoque2/.local/lib/python3.6/site-packages/django/db/utils.py", line 125, in load_backend
) from e_user
django.core.exceptions.ImproperlyConfigured: 'django.db.backends.postgis' isn't an available database backend.
Try using 'django.db.backends.XXX', where XXX is one of:
'mysql', 'oracle', 'postgresql', 'sqlite3'
here is my configuration in settings.py:
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'django.contrib.gis',
'world',
]
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgis',
'NAME': 'XXXX', #redacted
'USER': 'XXXX', #redacted
'PASSWORD': 'XXXX', #redacted
'HOST': 'localhost',
'PORT': '5432',
}
}
I dealt with this problem originally when I had django 1.11 on python2, but if I even use python3 I still get the error. When I run
python3 -m django version
I get '2.1.3'. I am not sure why django 2.1.3 will not take postgis as a backend even though the tutorial tells me it does. Is there perhaps something wrong with my django installation such that when I run
django-admin
it runs the 1.11 script instead of the 2.1.3? I am quite lost and this is quite frustrating.
The postgis backend is in django.contrib.gis, not django.db:
'ENGINE': 'django.contrib.gis.db.backends.postgis',

Delete Django Migrations

I changed databases from mysql to postgre. Since there was no data in teh db yet, I just deleted the migrations folders for each of the apps. When I ran makemigrations afterwards though, I got this error:
/theme/admin.py", line 2, in <module>
from models import theme, theme_file
ImportError: No module named 'models'
Everything worked fine before, nothing changed in the code other than the migrations folders being cleaned.
Any ideas?
/Users/jl/.virtualenvs/bolts3/bin/python /Users/jl/Desktop/Bolts/manage.py runserver 8000
Unhandled exception in thread started by <function check_errors.<locals>.wrapper at 0x108e15ae8>
Traceback (most recent call last):
File "/Users/jl/.virtualenvs/bolts3/lib/python3.5/site-packages/django/utils/autoreload.py", line 226, in wrapper
fn(*args, **kwargs)
File "/Users/jl/.virtualenvs/bolts3/lib/python3.5/site-packages/django/core/management/commands/runserver.py", line 113, in inner_run
autoreload.raise_last_exception()
File "/Users/jl/.virtualenvs/bolts3/lib/python3.5/site-packages/django/utils/autoreload.py", line 249, in raise_last_exception
six.reraise(*_exception)
File "/Users/jl/.virtualenvs/bolts3/lib/python3.5/site-packages/django/utils/six.py", line 685, in reraise
raise value.with_traceback(tb)
File "/Users/jl/.virtualenvs/bolts3/lib/python3.5/site-packages/django/utils/autoreload.py", line 226, in wrapper
fn(*args, **kwargs)
File "/Users/jl/.virtualenvs/bolts3/lib/python3.5/site-packages/django/__init__.py", line 27, in setup
apps.populate(settings.INSTALLED_APPS)
File "/Users/jl/.virtualenvs/bolts3/lib/python3.5/site-packages/django/apps/registry.py", line 115, in populate
app_config.ready()
File "/Users/jl/.virtualenvs/bolts3/lib/python3.5/site-packages/django/contrib/admin/apps.py", line 23, in ready
self.module.autodiscover()
File "/Users/jl/.virtualenvs/bolts3/lib/python3.5/site-packages/django/contrib/admin/__init__.py", line 26, in autodiscover
autodiscover_modules('admin', register_to=site)
File "/Users/jl/.virtualenvs/bolts3/lib/python3.5/site-packages/django/utils/module_loading.py", line 50, in autodiscover_modules
import_module('%s.%s' % (app_config.name, module_to_search))
File "/Users/jl/.virtualenvs/bolts3/lib/python3.5/importlib/__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 986, in _gcd_import
File "<frozen importlib._bootstrap>", line 969, in _find_and_load
File "<frozen importlib._bootstrap>", line 958, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 673, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 662, in exec_module
File "<frozen importlib._bootstrap>", line 222, in _call_with_frames_removed
File "/Users/jl/Desktop/Bolts/theme/admin.py", line 2, in <module>
from models import theme, theme_file
ImportError: No module named 'models'
Just deleting the migrations will not fix the issue when you change database types. In your settings.py file, you must change the default database settings to point to your new PostgreSQL database, and also specify the schema, db user and password etc. Perhaps you haven't done this?
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql',
'NAME': 'mydatabase',
'USER': 'mydatabaseuser',
'PASSWORD': 'mypassword',
'HOST': '127.0.0.1',
'PORT': '5432',
}
}
See: https://docs.djangoproject.com/en/1.10/ref/settings/
Mmmm it would seem like you deleted a __init__.py file by accident?
Remember that a folder must have such file to be a python module, and when a folder it's a python module you can import from it.

Django Haystack ElasticSearch Python3

my plan is to get Django with an ElasticSearch backend running using Python3 on a Debian 7.5-64bit machine.
I'll explain every single step, cause i'm nor a professional admin, neither a ready developer.
Not to forget, i'm dealing with this problem the third evening and i feels like i have tried every single tip in the internet.
First, I unpacked, configured, made, made test, made install Python-3.4.1 in my /usr/local/. This created links/bins in usr/local/bin. So i created symlinks from /usr/bin to /usr/local/bin and "installed" different python3 (3.2 from within debian, and 3.4) with update-alternatives. I created alternatives for python3 and python3-config.
The same with Java 8u11 Server-JRE.
I went on installing Django 1.6.5, Haystack 2.1, pyelasticsearch 0.6.1 with at least EVERY pip installed in /usr/bin and /usr/local/bin (pip has also installed requests 2.3.0, simplejson 3.6.0, six 1.7.3).
Meanwhile i also installed pyes 0.99.2 and urllib3 1.9. Both with pip.
Django is configured and running, also apache with mod-wsgi modul. I created a django project and an app (no models yet).
Elasticsearch is also running, but without any indizes yet.
To my project/settings.py i edited and added:
INSTALLED_APPS = {...
'haystack'}
...
DATABASES = {
'default': {
'ENGINE': 'haystack.backends.elasticsearch_backend.ElasticsearchSearchEngine',
'URL': 'http://127.0.0.1:9200/',
'NAME': 'haystack',
}
...
}
HAYSTACK_CONNECTIONS = {
'default': {
'ENGINE': 'haystack.backends.elasticsearch_backend.ElasticsearchSearchEngine',
'URL': 'http://127.0.0.1:9200/',
'INDEX_NAME': 'haystack',
},
}
When i run ./manage.py from within projectfolder I get following error:
./manage.py syncdb
Traceback (most recent call last):
File "./manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "/usr/local/lib/python2.7/dist-packages/django/core/management/__init__.py", line 399, in execute_from_command_line
utility.execute()
File "/usr/local/lib/python2.7/dist-packages/django/core/management/__init__.py", line 392, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/usr/local/lib/python2.7/dist-packages/django/core/management/base.py", line 242, in run_from_argv
self.execute(*args, **options.__dict__)
File "/usr/local/lib/python2.7/dist-packages/django/core/management/base.py", line 280, in execute
translation.activate('en-us')
File "/usr/local/lib/python2.7/dist-packages/django/utils/translation/__init__.py", line 130, in activate
return _trans.activate(language)
File "/usr/local/lib/python2.7/dist-packages/django/utils/translation/trans_real.py", line 188, in activate
_active.value = translation(language)
File "/usr/local/lib/python2.7/dist-packages/django/utils/translation/trans_real.py", line 177, in translation
default_translation = _fetch(settings.LANGUAGE_CODE)
File "/usr/local/lib/python2.7/dist-packages/django/utils/translation/trans_real.py", line 159, in _fetch
app = import_module(appname)
File "/usr/local/lib/python2.7/dist-packages/django/utils/importlib.py", line 40, in import_module
__import__(name)
File "/usr/local/lib/python2.7/dist-packages/django/contrib/admin/__init__.py", line 6, in <module>
from django.contrib.admin.sites import AdminSite, site
File "/usr/local/lib/python2.7/dist-packages/django/contrib/admin/sites.py", line 4, in <module>
from django.contrib.admin.forms import AdminAuthenticationForm
File "/usr/local/lib/python2.7/dist-packages/django/contrib/admin/forms.py", line 6, in <module>
from django.contrib.auth.forms import AuthenticationForm
File "/usr/local/lib/python2.7/dist-packages/django/contrib/auth/forms.py", line 17, in <module>
from django.contrib.auth.models import User
File "/usr/local/lib/python2.7/dist-packages/django/contrib/auth/models.py", line 48, in <module>
class Permission(models.Model):
File "/usr/local/lib/python2.7/dist-packages/django/db/models/base.py", line 96, in __new__
new_class.add_to_class('_meta', Options(meta, **kwargs))
File "/usr/local/lib/python2.7/dist-packages/django/db/models/base.py", line 264, in add_to_class
value.contribute_to_class(cls, name)
File "/usr/local/lib/python2.7/dist-packages/django/db/models/options.py", line 124, in contribute_to_class
self.db_table = truncate_name(self.db_table, connection.ops.max_name_length())
File "/usr/local/lib/python2.7/dist-packages/django/db/__init__.py", line 34, in __getattr__
return getattr(connections[DEFAULT_DB_ALIAS], item)
File "/usr/local/lib/python2.7/dist-packages/django/db/utils.py", line 198, in __getitem__
backend = load_backend(db['ENGINE'])
File "/usr/local/lib/python2.7/dist-packages/django/db/utils.py", line 131, in load_backend
raise ImproperlyConfigured(error_msg)
django.core.exceptions.ImproperlyConfigured: 'haystack.backends.elasticsearch_backend.ElasticsearchSearchEngine' isn't an available database backend.
Try using 'django.db.backends.XXX', where XXX is one of:
u'mysql', u'oracle', u'postgresql_psycopg2', u'sqlite3'
Error was: No module named ElasticsearchSearchEngine.base
And like the shebang in manage.py says, this so uses python2.7.
Then forcing my python 3.4 interpeter:
python3 ./manage.py syncdb
Traceback (most recent call last):
File "<frozen importlib._bootstrap>", line 2218, in _find_and_load_unlocked
AttributeError: 'module' object has no attribute '__path__'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/usr/local/lib/python3.4/site-packages/django/db/utils.py", line 113, in load_backend
return import_module('%s.base' % backend_name)
File "/usr/local/lib/python3.4/importlib/__init__.py", line 109, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 2254, in _gcd_import
File "<frozen importlib._bootstrap>", line 2237, in _find_and_load
File "<frozen importlib._bootstrap>", line 2212, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 321, in _call_with_frames_removed
File "<frozen importlib._bootstrap>", line 2254, in _gcd_import
File "<frozen importlib._bootstrap>", line 2237, in _find_and_load
File "<frozen importlib._bootstrap>", line 2221, in _find_and_load_unlocked
ImportError: No module named 'haystack.backends.elasticsearch_backend.ElasticsearchSearchEngine'; 'haystack.backends.elasticsearch_backend' is not a package
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "./manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "/usr/local/lib/python3.4/site-packages/django/core/management/__init__.py", line 399, in execute_from_command_line
utility.execute()
File "/usr/local/lib/python3.4/site-packages/django/core/management/__init__.py", line 392, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/usr/local/lib/python3.4/site-packages/django/core/management/base.py", line 242, in run_from_argv
self.execute(*args, **options.__dict__)
File "/usr/local/lib/python3.4/site-packages/django/core/management/base.py", line 280, in execute
translation.activate('en-us')
File "/usr/local/lib/python3.4/site-packages/django/utils/translation/__init__.py", line 130, in activate
return _trans.activate(language)
File "/usr/local/lib/python3.4/site-packages/django/utils/translation/trans_real.py", line 188, in activate
_active.value = translation(language)
File "/usr/local/lib/python3.4/site-packages/django/utils/translation/trans_real.py", line 177, in translation
default_translation = _fetch(settings.LANGUAGE_CODE)
File "/usr/local/lib/python3.4/site-packages/django/utils/translation/trans_real.py", line 159, in _fetch
app = import_module(appname)
File "/usr/local/lib/python3.4/importlib/__init__.py", line 109, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 2254, in _gcd_import
File "<frozen importlib._bootstrap>", line 2237, in _find_and_load
File "<frozen importlib._bootstrap>", line 2226, 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 1471, in exec_module
File "<frozen importlib._bootstrap>", line 321, in _call_with_frames_removed
File "/usr/local/lib/python3.4/site-packages/django/contrib/admin/__init__.py", line 6, in <module>
from django.contrib.admin.sites import AdminSite, site
File "/usr/local/lib/python3.4/site-packages/django/contrib/admin/sites.py", line 4, in <module>
from django.contrib.admin.forms import AdminAuthenticationForm
File "/usr/local/lib/python3.4/site-packages/django/contrib/admin/forms.py", line 6, in <module>
from django.contrib.auth.forms import AuthenticationForm
File "/usr/local/lib/python3.4/site-packages/django/contrib/auth/forms.py", line 17, in <module>
from django.contrib.auth.models import User
File "/usr/local/lib/python3.4/site-packages/django/contrib/auth/models.py", line 48, in <module>
class Permission(models.Model):
File "/usr/local/lib/python3.4/site-packages/django/db/models/base.py", line 96, in __new__
new_class.add_to_class('_meta', Options(meta, **kwargs))
File "/usr/local/lib/python3.4/site-packages/django/db/models/base.py", line 264, in add_to_class
value.contribute_to_class(cls, name)
File "/usr/local/lib/python3.4/site-packages/django/db/models/options.py", line 124, in contribute_to_class
self.db_table = truncate_name(self.db_table, connection.ops.max_name_length())
File "/usr/local/lib/python3.4/site-packages/django/db/__init__.py", line 34, in __getattr__
return getattr(connections[DEFAULT_DB_ALIAS], item)
File "/usr/local/lib/python3.4/site-packages/django/db/utils.py", line 198, in __getitem__
backend = load_backend(db['ENGINE'])
File "/usr/local/lib/python3.4/site-packages/django/db/utils.py", line 131, in load_backend
raise ImproperlyConfigured(error_msg)
django.core.exceptions.ImproperlyConfigured: 'haystack.backends.elasticsearch_backend.ElasticsearchSearchEngine' isn't an available database backend.
Try using 'django.db.backends.XXX', where XXX is one of:
'mysql', 'oracle', 'postgresql_psycopg2', 'sqlite3'
Error was: No module named 'haystack.backends.elasticsearch_backend.ElasticsearchSearchEngine'; 'haystack.backends.elasticsearch_backend' is not a package
A ls shows, that the file is there, and with an editor i see, that the class exists
/usr/local/lib/python3.4/site-packages/haystack/backends/elasticsearch_backend.py
Did I forget ANYTHING? Should there be anything in "PYTHONPATH" which is under python-lib directory? Which information could also be important?
At least: Is this setup even possible? Did i understand the structure of django-haystack and database-backend correct?
Please help me. I'm tired of and done with the docu and samples from django, haystack, elasticsearch and the most targeting google hits.
syncdb command will try to sync your models with the database. Django is not able to interpret ElasticsearchSearchEngine as a database. You should use correct ENGINE value corresponding to the database you are using.
e.g. For MySQL
ENGINE='django.db.backends.mysql'
Do you intend to use database at all? If not then do not run syncdb.
Your database setting is wrong. You should use any of the database engine here like :
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': 'mydatabase',
}
}
if you choose to use sqlite database in your project.

NameError: name PositiveSmallIntegerField is not defined

Django 1.5 & Python 3.2.3, on Ubuntu 12.04.
Very odd error when trying to syncdb my DB. I've got some fields that don't look wrong but Django's spitting out this error message when I run python3 manage.py sqlall..
NameError: name 'PositiveSmallIntegerField' is not defined
Huh? I tried Googling this, but there's not a single thing about it anywhere. So I'm guessing I've made some stupid mistake but I can't see it. My models.py looks like this:
from django.db import models
class Song(models.Model):
own = models.BooleanField(default=True)
heard = models.DateTimeField(blank=True,null=True)
release_date = models.DateField(blank=True,null=True)
style = models.CharField(max_length=255,blank=True,null=True)
artist = models.CharField(max_length=255,blank=True,null=True)
featuring = models.CharField(max_length=255,blank=True,null=True)
title = models.CharField(max_length=255,blank=True,null=True)
listen = models.URLField(max_length=255,blank=True,null=True)
highest_chart_pos = models.PositiveSmallIntegerField()
note = models.TextField(blank=True,null=True)
That's all there is to it, and I copy-n-pasted PositiveSmallIntegerField straight from the Django documentation so I know there isn't a typo in it that I'm overlooking. So, how is PositiveSmallIntegerField not defined?
Throwing this in here because I found myself with the same error, creating a model for a
song, too!
from django.db import models
class Track(models.Model):
release = models.ForeignKey('Release', on_delete=models.CASCADE)
position = models.PositiveSmallIntegerField()
number = PositiveSmallIntegerField()
name = models.CharField(max_length=100)
length = models.DurationField()
There is a slight difference, here. I left out the namespace of models. before my PositiveSmallIntegerField. It looks like you didn't do that, above, but maybe someone else with a similar error will made my mistake, too.
Here was my stacktrace:
(env) Cam#cambook:~/Sites/juke% python manage.py makemigrations playlists
Traceback (most recent call last):
File "manage.py", line 15, in <module>
execute_from_command_line(sys.argv)
File "/Users/Cam/Sites/juke/env/lib/python3.6/site-packages/django/core/management/__init__.py", line 371, in execute_from_command_line
utility.execute()
File "/Users/Cam/Sites/juke/env/lib/python3.6/site-packages/django/core/management/__init__.py", line 347, in execute
django.setup()
File "/Users/Cam/Sites/juke/env/lib/python3.6/site-packages/django/__init__.py", line 24, in setup
apps.populate(settings.INSTALLED_APPS)
File "/Users/Cam/Sites/juke/env/lib/python3.6/site-packages/django/apps/registry.py", line 112, in populate
app_config.import_models()
File "/Users/Cam/Sites/juke/env/lib/python3.6/site-packages/django/apps/config.py", line 198, in import_models
self.models_module = import_module(models_module_name)
File "/usr/local/Cellar/python/3.6.5_1/Frameworks/Python.framework/Versions/3.6/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 "/Users/Cam/Sites/juke/playlists/models.py", line 60, in <module>
class Track(models.Model):
File "/Users/Cam/Sites/juke/playlists/models.py", line 63, in Track
number = PositiveSmallIntegerField()
NameError: name 'PositiveSmallIntegerField' is not defined