no South database module 'south.db.sqlite3' - python

I'm trying to run
python manage.py syncdb
but i'm getting this error:
There is no South database module 'south.db.sqlite3'
This is my settings.py
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
}
}
SOUTH_DATABASE_ADAPTERS = {
'default': 'south.db.sqlite3'
}

You may be able to address this by specifically installing Django 1.6 with pip install django==1.6.
You may also have luck if you add
SOUTH_DATABASE_ADAPTERS = {
'default': 'south.db.sqlite3'
}
If that don't work may be your answer can be here :
http://answerhub.com/qa/questions/28185/how-do-i-get-syncdb-to-work-im-getting-there-is-no.html

Related

Adding existing sqlite3 database to Django App

Trying to follow this tutorial: https://knivets.com/how-to-integrate-django-with-existing-database/
and this SO: Using existing database in Django
My settings.py databases setup:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
},
# existing db I wan't to add
'articles': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': os.path.join(BASE_DIR, 'articles.sqlite3'),
}
}
It does detect and generates a model based on the table I'm interested in. I've added this model to models.py and
python manage.py dbshell --database=articles
does show the table and that it holds data. However, in Django /admin the table shows up but breaks when I try to add to it and none of the existing data appears. This is the error that it throws:
OperationalError at /admin/core/articles/
no such table: articles
I appreciate any help ya'll can offer here.

django-rosetta error: You can't use the CacheRosettaStorage

I'm using django-rosetta app, it works on development without a CACHES setting, but on prod I've this setting as follow:
CACHES = {
'default': {
'BACKEND': 'django.core.cache.backends.memcached.MemcachedCache',
'LOCATION': '127.0.0.1:11211',
}
}
The problem is that under prod it raises me
django.core.exceptions.ImproperlyConfigured:
You can't use the CacheRosettaStorage if your cache isn't correctly set up,
please double check your Django DATABASES setting and that the cache server is responding
The database setting is simple as
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
}
}
So, as the exception message sais:
double check your Django DATABASES setting and that the cache server is responding
I did it, even my memchached was working correctly I decided reinstall it, and, as magic art, it worked!
Before that I changed my CACHES
CACHES = {
'default': {
'BACKEND': 'django.core.cache.backends.memcached.MemcachedCache',
'LOCATION': '127.0.0.1:11211',
},
'rosetta': {
'BACKEND': 'django.core.cache.backends.filebased.FileBasedCache',
'LOCATION': '/var/tmp/django_cache',
}
}
Django rosetta will use a key rosetta if a cache with this name exists, or default if not. With the FileBasedCache it wasn't launch any error, so I realized the problem was with MemcachedCache. But, after reinstall it, it worked.

How to make two django projects share the same database

I need to make two separate Django projects share the same database. In project_1 I have models creating objects that I need to use in project_2 (mostly images).
The tree structure of project_1_2 is:
project_1/
manage.py
settings.py
project_1_app1/
...
...
project_2/
manage.py
settings.py
project_2_app1/
...
...
Which is the best approach?
EDIT: I'm using sqlite3 in my development environment.
I'd like to keep my two django projects as stand-alone projects (so that both can be upgraded safely from their respective repositories).
# in project_1/settings.py
import os
PROJECT_ROOT = os.path.abspath(os.path.dirname(__file__))
..
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': os.path.join(PROJECT_ROOT, 'development.db'),
},
}
...
# in project_2/settings.py
import os
PROJECT_ROOT = os.path.abspath(os.path.dirname(__file__))
..
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': os.path.join(PROJECT_ROOT, 'development.db'),
},
}
...
In this way, each project has its own development.db (the one that I need to be shared):
project_1/development.db
project_2/development.db
but I guess I need to do something more to make it shared (and unique).
The best for me would be to keep the development.db at project_1/ path and thus set the project_2/settings.py DATABASES to point to project_1/development.db.
You can simply define the same database in DATABASES in your settings.py. So, if your database is PostgreSQL, you could do something like this:
# in project_1/settings.py
DATABASES = {
'default': {
'NAME': 'common_db',
'ENGINE': 'django.db.backends.postgresql',
'USER': 'project_1_user',
'PASSWORD': 'strong_password_1'
},
}
# in project_2/settings.py
DATABASES = {
'default': {
'NAME': 'common_db',
'ENGINE': 'django.db.backends.postgresql',
'USER': 'project_2_user',
'PASSWORD': 'strong_password_2'
},
}
Note that both database users (project_1_user and project_2_user) should have the appropriate privileges on the database you wish to use. Or you could instead use the same user for both projects.
If you want to have more than just one database per project, you should take a look at the docs for multiple databases.
On another matter, since you share data, I guess you share functionalities as well. So for example, if project_1_app1 and project_2_app1 do same (or similar) things, it seems they could instead be a single reusable app.
Edit
Since you use sqlite3, you should ensure the path you use is the same. So, assuming that project_1 and project_2 are siblings, like so:
projects
project_1
settings.py
...
project_2
settings.py
...
you should try this:
# project_1/settings.py
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': os.path.join(PROJECT_ROOT, 'development.db'),
},
}
# project_2/settings.py
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': os.path.join(
os.path.dirname(os.path.dirname(PROJECT_ROOT)),
'project_1',
'development.db'
),
},
}
This would give the structure you ask for. Note however that the projects are not both "standalone". project_2 is clearly dependent on project_1's database.
In any case, perhaps, you should also take a look at the os.path module for more info.
You just need to declare in your model in class meta the attribute db_table with a name diferent the name of app + model (Which are automatically generated by Django) the twice projects need the same models. before the run makemigrations and migrate.
class MyModel(models.Model):
class Meta:
db_table = 'MyModel'

How to set storage engine in Django with MySQL connector/python as backend

I tried setting
DATABASES = {
'default': {
'NAME': 'db',
'ENGINE': 'mysql.connector.django',
'USER': 'dbuser',
'PASSWORD': 'dbpass',
'OPTIONS': {
'autocommit': True,
'init_command' : 'SET storage_engine=INNODB',
},
}
}
(UPD: updated the above code so ppl won't get confused that I am not using django settings the right way)
in Django settings, but this backend doesn't accept such connection option...
http://dev.mysql.com/doc/connector-python/en/connector-python-connectargs.html
is there any other way of doing this?
First, to use MySQL Connector/Python Django backend, you have to set the ENGINE setting to mysql.connector.django:
DATABASE = {
'default': {
..
'ENGINE': 'mysql.connector.django',
..
}
}
Indeed, MySQL Connector/Python does not have the init_command connection argument. I can see value in adding an option for setting the default storage engine in the Django OPTIONS though. If you really want it, I would suggest opening a feature request on http://bugs.mysql.com.
Small note that MySQL 5.6 (and if you start out, you should use this version) has storage engine set to InnoDB by default.
You need to set the entire setting:
DATABASES = {
'default': {
'NAME': "MyDatabaseName,
'ENGINE': 'django.db.backends.mysql',
'USER': "MyUsername",
'PASSWORD': "MyPassword",
'HOST': "MyHostName",
'OPTIONS': {'init_command': 'SET storage_engine=INNODB'},
}
}

Configure Django with MS SQL Server database

I'm setting up a Django application and I want to use SQL Server 2012 for my database.
To configure my website I'm following this section of the official Django documentation.
In the section Database setup I found instructions for changing RDBMS.
And in settings.py file I found these instructions for setting up Django with SQlite.
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
}
}
How I can change this configuration to use SQL Server 2012 instead?
Looks like you'll need django-mssql which requires django 1.4 or below:
http://django-mssql.readthedocs.org/en/latest/
It has a pip package: https://pypi.python.org/pypi/django-mssql
Then include in your settings.py:
DATABASES = {
'default': {
'NAME': 'my_database',
'ENGINE': 'sqlserver_ado',
'HOST': 'dbserver\\ss2008',
'USER': '',
'PASSWORD': '',
}
}

Categories

Resources