UPDATE for close - I think I go through it and it was a bit of stupidity on my behalf.
python manage.py inspectdb > models.py
I was forgetting to pipe the output to a file!
I've dumped that into my app/models.py and now I'm just trying to get it running from there but going further.
I'm trying to get django running against an SQL Server 2008 R2 server.
I've figured out the FreeTDS/unixODBC connections. I can successfully do an isql and tsql query against the database.
I've been able to do a connection directly in python like so -
import pyodbc
cnxn = pyodbc.connect('DRIVER=FreeTDS;SERVER=servername;DATABASE=dbname;UID=user;PWD=pass;TDS_Version=8.0;')
cursor = cnxn.cursor()
result = cursor.execute("select name from tablea where name = 'hello'")
print result
If I do an inspectdb in django shell it's fine. It returns 70+ tables and their layout perfectly ok.
once I try to do a syndb it's spilling back the following error -
Creating tables ...
Creating table django_admin_log
Creating table auth_permission
Creating table auth_group_permissions
Creating table auth_group
Creating table auth_user_groups
Creating table auth_user_user_permissions
Creating table auth_user
Creating table django_content_type
Creating table django_session
Traceback (most recent call last):
File "manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "/usr/local/lib/python2.6/dist-packages/django/core/management/__init__.py", line 399, in execute_from_command_line
utility.execute()
File "/usr/local/lib/python2.6/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.6/dist-packages/django/core/management/base.py", line 242, in run_from_argv
self.execute(*args, **options.__dict__)
File "/usr/local/lib/python2.6/dist-packages/django/core/management/base.py", line 285, in execute
output = self.handle(*args, **options)
File "/usr/local/lib/python2.6/dist-packages/django/core/management/base.py", line 415, in handle
return self.handle_noargs(**options)
File "/usr/local/lib/python2.6/dist-packages/django/core/management/commands/syncdb.py", line 112, in handle_noargs
emit_post_sync_signal(created_models, verbosity, interactive, db)
File "/usr/local/lib/python2.6/dist-packages/django/core/management/sql.py", line 216, in emit_post_sync_signal
interactive=interactive, db=db)
File "/usr/local/lib/python2.6/dist-packages/django/dispatch/dispatcher.py", line 185, in send
response = receiver(signal=self, sender=sender, **named)
File "/usr/local/lib/python2.6/dist-packages/django/contrib/auth/management/__init__.py", line 82, in create_permissions
ctype = ContentType.objects.db_manager(db).get_for_model(klass)
File "/usr/local/lib/python2.6/dist-packages/django/contrib/contenttypes/models.py", line 47, in get_for_model
defaults = {'name': smart_text(opts.verbose_name_raw)},
File "/usr/local/lib/python2.6/dist-packages/django/db/models/manager.py", line 154, in get_or_create
return self.get_queryset().get_or_create(**kwargs)
File "/usr/local/lib/python2.6/dist-packages/django/db/models/query.py", line 373, in get_or_create
return self.get(**lookup), False
File "/usr/local/lib/python2.6/dist-packages/django/db/models/query.py", line 301, in get
num = len(clone)
File "/usr/local/lib/python2.6/dist-packages/django/db/models/query.py", line 77, in __len__
self._fetch_all()
File "/usr/local/lib/python2.6/dist-packages/django/db/models/query.py", line 854, in _fetch_all
self._result_cache = list(self.iterator())
File "/usr/local/lib/python2.6/dist-packages/django/db/models/query.py", line 220, in iterator
for row in compiler.results_iter():
File "/usr/local/lib/python2.6/dist-packages/django/db/models/sql/compiler.py", line 710, in results_iter
for rows in self.execute_sql(MULTI):
File "/usr/local/lib/python2.6/dist-packages/django/db/models/sql/compiler.py", line 771, in execute_sql
sql, params = self.as_sql()
File "/usr/local/lib/python2.6/dist-packages/sql_server/pyodbc/compiler.py", line 48, in as_sql
self._get_ordering(out_cols, supports_offset_clause or not do_offset)
File "/usr/local/lib/python2.6/dist-packages/sql_server/pyodbc/compiler.py", line 154, in _get_ordering
ordering, ordering_group_by = self.get_ordering()
ValueError: too many values to unpack
similarily if I try to do a query in django like so -
from myapp.models import tablea
tablea.objects.filter(id=5)
It fails with the following error message -
Traceback (most recent call last):
File "<console>", line 1, in <module>
File "/usr/local/lib/python2.6/dist-packages/django/db/models/query.py", line 71, in __repr__
data = list(self[:REPR_OUTPUT_SIZE + 1])
File "/usr/local/lib/python2.6/dist-packages/django/db/models/query.py", line 96, in __iter__
self._fetch_all()
File "/usr/local/lib/python2.6/dist-packages/django/db/models/query.py", line 854, in _fetch_all
self._result_cache = list(self.iterator())
File "/usr/local/lib/python2.6/dist-packages/django/db/models/query.py", line 220, in iterator
for row in compiler.results_iter():
File "/usr/local/lib/python2.6/dist-packages/django/db/models/sql/compiler.py", line 710, in results_iter
for rows in self.execute_sql(MULTI):
File "/usr/local/lib/python2.6/dist-packages/django/db/models/sql/compiler.py", line 771, in execute_sql
sql, params = self.as_sql()
File "/usr/local/lib/python2.6/dist-packages/sql_server/pyodbc/compiler.py", line 48, in as_sql
self._get_ordering(out_cols, supports_offset_clause or not do_offset)
File "/usr/local/lib/python2.6/dist-packages/sql_server/pyodbc/compiler.py", line 154, in _get_ordering
ordering, ordering_group_by = self.get_ordering()
ValueError: too many values to unpack
I'm not convinced these errors are related to the other thread found here -
ValueError: Too many values to unpack Django
But I'm no expert so I could be wrong. I know I did try to change my password and it won't let me connect similar error message -
>>> u = User.objects.get(username="user")
Traceback (most recent call last):
File "<console>", line 1, in <module>
File "/usr/local/lib/python2.6/dist-packages/django/db/models/manager.py", line 151, in get
return self.get_queryset().get(*args, **kwargs)
File "/usr/local/lib/python2.6/dist-packages/django/db/models/query.py", line 301, in get
num = len(clone)
File "/usr/local/lib/python2.6/dist-packages/django/db/models/query.py", line 77, in __len__
self._fetch_all()
File "/usr/local/lib/python2.6/dist-packages/django/db/models/query.py", line 854, in _fetch_all
self._result_cache = list(self.iterator())
File "/usr/local/lib/python2.6/dist-packages/django/db/models/query.py", line 220, in iterator
for row in compiler.results_iter():
File "/usr/local/lib/python2.6/dist-packages/django/db/models/sql/compiler.py", line 710, in results_iter
for rows in self.execute_sql(MULTI):
File "/usr/local/lib/python2.6/dist-packages/django/db/models/sql/compiler.py", line 771, in execute_sql
sql, params = self.as_sql()
File "/usr/local/lib/python2.6/dist-packages/sql_server/pyodbc/compiler.py", line 48, in as_sql
self._get_ordering(out_cols, supports_offset_clause or not do_offset)
File "/usr/local/lib/python2.6/dist-packages/sql_server/pyodbc/compiler.py", line 154, in _get_ordering
ordering, ordering_group_by = self.get_ordering()
ValueError: too many values to unpack
edit to add - when doing a query my model definition is as follows -
from django.db import models
# Create your models here.
class tablea(models.Model):
tablea_id = models.IntegerField()
tablea_name = models.CharField(max_length=32)
tablea_duration = models.IntegerField()
class Meta:
db_table = u'tablea'
def __unicode__(self):
return self.tablea_name, tablea_duration
edit to add that I've done a complete fresh reinstall. Wiped the VM and brought it back to life. Here's a breakdown of the steps done
apt-get install gcc g++ make python-dev
download unixODBC
tar xzvf unixODBC-2.3.2.tar.gz
./configure
make
makeinstall
download FreeTDS
tar xzvf freetds-stable.tgz
./configure --with-tdsver=8.0 --with-unixodbc=usr/local
make
make install
ldconfig -v
odbc.ini
[mssql]
Description = MSSQL Server
Driver = freetds
Database = database
Server = server
Port = 1433
TDS_Version = 8.0
odbcinst.ini
[freetds]
Description = MS SQL database access with Free TDS
Driver = /usr/local/lib/libtdsodbc.so
Setup = /usr/local/lib/libtdsS.so
UsageCount = 1
freetds.conf
[mssql]
host = server
port = 1433
tds version = 8.0
tsql -S mssql -U user -P password works
isql -v mssql user password works (for some reason simple isql -v mssql does not)
apt-get install python-setuptools
easy_install pip
pip install pyodbc
pip install Django==1.6
pip install django-pyodbc-azure
settings.py
DATABASES = {
'default': {
'ENGINE': 'sql_server.pyodbc',
'HOST': "server\instance",
'USER': "username",
'PASSWORD': "password",
'NAME': "database",
'OPTIONS': {
'host_is_server': True,
'driver': 'FreeTDS',
'dsn': 'MSSQL',
},
}
}
It's a version incompatibility issue.
Django 1.6 changed the kind of value returned by django.db.models.sql.compiler.SQLCompiler.get_ordering. It returns a 3-element tuple, but pyodbc unpacks just two elements.
If you look at Django 1.5 version you see that it used to return a 2-element tuple as pyodbc expects.
Related
I am trying to perform a sudo ./manage.py dumpdata on a mssql db from my django project, but keep getting:
Traceback (most recent call last):
File "./manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "/opt/bitnami/python/lib/python2.7/site-packages/django/core/management/__init__.py", line 385, in execute_from_command_line
utility.execute()
File "/opt/bitnami/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 "/opt/bitnami/python/lib/python2.7/site-packages/django/core/management/base.py", line 288, in run_from_argv
self.execute(*args, **options.__dict__)
File "/opt/bitnami/python/lib/python2.7/site-packages/django/core/management/base.py", line 338, in execute
output = self.handle(*args, **options)
File "/opt/bitnami/python/lib/python2.7/site-packages/django/core/management/commands/dumpdata.py", line 158, in handle
stream=self.stdout)
File "/opt/bitnami/python/lib/python2.7/site-packages/django/core/serializers/__init__.py", line 128, in serialize
s.serialize(queryset, **options)
File "/opt/bitnami/python/lib/python2.7/site-packages/django/core/serializers/base.py", line 52, in serialize
for obj in queryset:
File "/opt/bitnami/python/lib/python2.7/site-packages/django/core/management/commands/dumpdata.py", line 150, in get_objects
for obj in queryset.iterator():
File "/opt/bitnami/python/lib/python2.7/site-packages/django/db/models/query.py", line 265, in iterator
for row in compiler.results_iter():
File "/opt/bitnami/python/lib/python2.7/site-packages/django/db/models/sql/compiler.py", line 701, in results_iter
for rows in self.execute_sql(MULTI):
File "/opt/bitnami/python/lib/python2.7/site-packages/django/db/models/sql/compiler.py", line 785, in execute_sql
cursor = self.connection.cursor()
File "/opt/bitnami/python/lib/python2.7/site-packages/django/db/backends/__init__.py", line 165, in cursor
cursor = self.make_debug_cursor(self._cursor())
File "/opt/bitnami/python/lib/python2.7/site-packages/sql_server/pyodbc/base.py", line 230, in _cursor
autocommit=autocommit)
pyodbc.Error: ('IM002', '[IM002] [unixODBC][Driver Manager]Data source name not found, and no default driver specified (0) (SQLDriverConnect)')
I have done the configuration mentioned in https://code.google.com/p/django-pyodbc/wiki/FreeTDS, and I get all the test working (FreeTDS & ODBC).
Here is my current settings.py database config:
DATABASES = {
...
'vcoe':
{
'ENGINE' : 'sql_server.pyodbc',
'NAME' : 'VOIP',
'USER' : '******',
'PASSWORD' : '******',
'OPTIONS' : {
'driver': 'FreeTDS',
'dsn': 'VCOE',
}
}
}
DATABASE_ENGINE = 'sql_server.pyodbc'
DATABASE_NAME = 'VOIP'
DATABASE_USER = '******'
DATABASE_PASSWORD = '******'
DATABASE_OPTIONS = {
'driver': 'FreeTDS',
'dsn': 'VCOE', # ODBC DSN name defined in your odbc.ini
}
When I try and run ./manage.py test I get:
Traceback (most recent call last):
File "./manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "/opt/bitnami/python/lib/python2.7/site-packages/django/core/management/__init__.py", line 385, in execute_from_command_line
utility.execute()
File "/opt/bitnami/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 "/opt/bitnami/python/lib/python2.7/site-packages/django/core/management/commands/test.py", line 50, in run_from_argv
super(Command, self).run_from_argv(argv)
File "/opt/bitnami/python/lib/python2.7/site-packages/django/core/management/base.py", line 288, in run_from_argv
self.execute(*args, **options.__dict__)
File "/opt/bitnami/python/lib/python2.7/site-packages/django/core/management/commands/test.py", line 71, in execute
super(Command, self).execute(*args, **options)
File "/opt/bitnami/python/lib/python2.7/site-packages/django/core/management/base.py", line 338, in execute
output = self.handle(*args, **options)
File "/opt/bitnami/python/lib/python2.7/site-packages/django/core/management/commands/test.py", line 88, in handle
failures = test_runner.run_tests(test_labels)
File "/opt/bitnami/python/lib/python2.7/site-packages/django/test/runner.py", line 147, in run_tests
old_config = self.setup_databases()
File "/opt/bitnami/python/lib/python2.7/site-packages/django/test/runner.py", line 109, in setup_databases
return setup_databases(self.verbosity, self.interactive, **kwargs)
File "/opt/bitnami/python/lib/python2.7/site-packages/django/test/runner.py", line 299, in setup_databases
serialize=connection.settings_dict.get("TEST", {}).get("SERIALIZE", True),
File "/opt/bitnami/python/lib/python2.7/site-packages/django/db/backends/creation.py", line 362, in create_test_db
self._create_test_db(verbosity, autoclobber)
File "/opt/bitnami/python/lib/python2.7/site-packages/django/db/backends/creation.py", line 455, in _create_test_db
with self._nodb_connection.cursor() as cursor:
File "/opt/bitnami/python/lib/python2.7/site-packages/django/db/backends/__init__.py", line 167, in cursor
cursor = utils.CursorWrapper(self._cursor(), self)
File "/opt/bitnami/python/lib/python2.7/site-packages/sql_server/pyodbc/base.py", line 181, in _cursor
raise ImproperlyConfigured('You need to specify NAME in your Django settings file.')
django.core.exceptions.ImproperlyConfigured: You need to specify NAME in your Django settings file.
I have tried to remove the DATABASES = {...} section and only leave the DATABASE_XXX but get:
django.core.exceptions.ImproperlyConfigured: settings.DATABASES is improperly configured. Please supply the ENGINE value. Check settings documentation for more details.
Im currently using on client:
Ubuntu 14.04.1 LTS
Python 2.7.6
Django 1.7.8
pyodbc==3.0.10
django-pyodbc==0.2.8
Server I'm reaching is:
Microsoft Server 2003 running: MSSQL 2005
Here is /etc/odbcinst.ini:
[FreeTDS]
Description = TDS driver (Sybase/MS SQL)
Driver = /usr/lib/x86_64-linux-gnu/odbc/libtdsodbc.so
Setup = /usr/lib/x86_64-linux-gnu/odbc/libtdsS.so
CPTimeout =
CPReuse =
Double checked path, all files are present
Here is my /etc/odbc.ini:
[ODBC Data Sources]
ODBCNAME = Microsoft SQL Server
[VCOE]
Driver = FreeTDS
Description = VOIP Legacy Database
Trace = No
Servername = VOIP
Database = VOIP
[Default]
Driver = /usr/lib/x86_64-linux-gnu/odbc/libtdsodbc.so
here is my /etc/freetds/freetds.conf:
[VOIP]
host = 142.117.139.***
port = 1433
tds version = 8.0
You're using a very, very old version of django-pyodbc that is no longer maintained. That was last updated in 2011. I've had problems with older versions and using dumpdata and dbshell. I would recommend using this version, actively maintained, which has been working wonderfully for me in several Django projects:
https://github.com/michiya/django-pyodbc-azure
Note, to install it, you'll have to do this, since you're not using Django 1.8:
pip install django-pyodbc-azure<1.8
Off-topic: I'd recommend using Django 1.8.x if you're just starting on a project. While Django 1.7.x is still supported, Django 1.8.x is a long-term release, meaning it will be supported for at least three years. Good luck!
I have connected django with sql anywhere 11 database, I have follow the instructions on the page SQL Anywhere Django Driver from github.
I have created the database with this command:
C:\>dbinit -z UCA django.db --> (database created successful)
I have started the Database Server with command:
C:\>dbsrv11 django.db --> (database server started successful)
I have created my project with:
C:\>django-admin.py startproject mysite (at this point all it's ok)
I have edited the file mysite/mysite/settings.py and I have changed the DATABASES setting with this:
DATABASES = {
'default': {
'ENGINE': 'sqlany_django',
'NAME': 'django',
'USER': 'dba',
'PASSWORD': 'sql',
'OPTIONS': {'eng': 'django'}
}
}
When I want to sync database using this command:
c:/mysite>python manage.py syncdb
the prompt show me a error message (the error message is shown below)
I have connected Sybase Central to django.db I see the tables was created.
but when I try save data to the tables this data wasn't recorded
even when I have created the superuser with this command:
c:\mysite>python manage.py createsuperuser --username=joe --email=joe#example.com
Password:123
Password (again):123
Superuser created successfully.
I querying the datebase with:
select * from auth_user
No rows are shown
The data aren't saved
I have an environment for test with this features:
O.S.: Windows XP
DB Engine: SQL Anywhere 11 with EBF 3069
Python 2.7
Django 1.6.1
Setuptools installed
PIP installed
sqlanydb installed
sqlany-django installed
Here is the error message
C:\mysite>python manage.py syncdb
Creating tables ...
Creating table django_admin_log
Creating table auth_permission
Creating table auth_group_permissions
Creating table auth_group
Creating table auth_user_groups
Creating table auth_user_user_permissions
Creating table auth_user
Creating table django_content_type
Creating table django_session
Creating table Personal_persona
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_command_line
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 285,
in execute
output = self.handle(*args, **options)
File "C:\Python27\lib\site-packages\django\core\management\base.py", line 415,
in handle
return self.handle_noargs(**options)
File "C:\Python27\lib\site-packages\django\core\management\commands\syncdb.py"
, line 112, in handle_noargs
emit_post_sync_signal(created_models, verbosity, interactive, db)
File "C:\Python27\lib\site-packages\django\core\management\sql.py", line 216,
in emit_post_sync_signal
interactive=interactive, db=db)
File "C:\Python27\lib\site-packages\django\dispatch\dispatcher.py", line 185,
in send
response = receiver(signal=self, sender=sender, **named)
File "C:\Python27\lib\site-packages\django\contrib\auth\management\__init__.py
", line 101, in create_permissions
auth_app.Permission.objects.using(db).bulk_create(perms)
File "C:\Python27\lib\site-packages\django\db\models\query.py", line 356, in b
ulk_create
self._batched_insert(objs_without_pk, fields, batch_size)
File "C:\Python27\lib\site-packages\django\db\models\query.py", line 835, in _
batched_insert
using=self.db)
File "C:\Python27\lib\site-packages\django\db\models\manager.py", line 232, in
_insert
return insert_query(self.model, objs, fields, **kwargs)
File "C:\Python27\lib\site-packages\django\db\models\query.py", line 1511, in
insert_query
return query.get_compiler(using=using).execute_sql(return_id)
File "C:\Python27\lib\site-packages\django\db\models\sql\compiler.py", line 90
3, in execute_sql
cursor.execute(sql, params)
File "C:\Python27\lib\site-packages\django\db\backends\util.py", line 69, in e
xecute
return super(CursorDebugWrapper, self).execute(sql, params)
File "C:\Python27\lib\site-packages\django\db\backends\util.py", line 53, in e
xecute
return self.cursor.execute(sql, params)
File "C:\Python27\lib\site-packages\django\db\utils.py", line 99, in __exit__
six.reraise(dj_exc_type, dj_exc_value, traceback)
File "C:\Python27\lib\site-packages\django\db\backends\util.py", line 53, in e
xecute
return self.cursor.execute(sql, params)
File "C:\Python27\lib\site-packages\sqlany_django\base.py", line 87, in execut
e
ret = self.cursor.execute(trace(query), trace(args))
File "C:\Python27\lib\site-packages\sqlanydb.py", line 714, in execute
self.executemany(operation, [parameters])
File "C:\Python27\lib\site-packages\sqlanydb.py", line 685, in executemany
bind_count = self.api.sqlany_num_params(self.stmt)
File "C:\Python27\lib\site-packages\sqlanydb.py", line 619, in __stmt_get
self.handleerror(*self.parent.error())
File "C:\Python27\lib\site-packages\sqlanydb.py", line 613, in handleerror
eh(self.parent, self, errorclass, errorvalue)
File "C:\Python27\lib\site-packages\sqlanydb.py", line 342, in standardErrorHa
ndler
raise errorclass(errorvalue)
django.db.utils.OperationalError: Syntax error near ',' on line 1
Sorry, but the SQL Anywhere Django driver requires SQL Anywhere v12 or higher; you cannot use it with SQL Anywhere v11. I have confirmed that the driver uses features of the database server that were not supported in version 11.
Disclaimer: I work for SAP in SQL Anywhere engineering.
I can't overcome a problem with making new sqlite3 database under django 1.6 app. When I am doing python manage.py syncdb then it allows me to create some tables like:
Creating table django_admin_log
Creating table auth_permission
Creating table auth_group_permissions
Creating table auth_group
Creating table auth_user_groups
Creating table auth_user_user_permissions
Creating table auth_user
Creating table django_content_type
Creating table django_session
...but after some tracebacks it finish with an error:
Traceback (most recent call last):
File "manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "/usr/local/alwaysdata/python/django/1.6.1/django/core/management/__init_
_.py", line 399, in execute_from_command_line
utility.execute()
File "/usr/local/alwaysdata/python/django/1.6.1/django/core/management/__init_
_.py", line 392, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/usr/local/alwaysdata/python/django/1.6.1/django/core/management/base.py
", line 242, in run_from_argv
self.execute(*args, **options.__dict__)
File "/usr/local/alwaysdata/python/django/1.6.1/django/core/management/base.py
", line 285, in execute
output = self.handle(*args, **options)
File "/usr/local/alwaysdata/python/django/1.6.1/django/core/management/base.py
", line 415, in handle
return self.handle_noargs(**options)
File "/usr/local/alwaysdata/python/django/1.6.1/django/core/management/command
s/syncdb.py", line 112, in handle_noargs
emit_post_sync_signal(created_models, verbosity, interactive, db)
File "/usr/local/alwaysdata/python/django/1.6.1/django/core/management/sql.py"
, line 216, in emit_post_sync_signal
interactive=interactive, db=db)
File "/usr/local/alwaysdata/python/django/1.6.1/django/dispatch/dispatcher.py"
, line 185, in send
response = receiver(signal=self, sender=sender, **named)
File "/usr/local/alwaysdata/python/django/1.6.1/django/contrib/auth/management
/__init__.py", line 82, in create_permissions
ctype = ContentType.objects.db_manager(db).get_for_model(klass)
File "/usr/local/alwaysdata/python/django/1.6.1/django/contrib/contenttypes/mo
dels.py", line 47, in get_for_model
defaults = {'name': smart_text(opts.verbose_name_raw)},
File "/usr/local/alwaysdata/python/django/1.6.1/django/db/models/manager.py",
line 154, in get_or_create
return self.get_queryset().get_or_create(**kwargs)
File "/usr/local/alwaysdata/python/django/1.6.1/django/db/models/query.py", li
ne 388, in get_or_create
six.reraise(*exc_info)
File "/usr/local/alwaysdata/python/django/1.6.1/django/db/models/query.py", li
ne 379, in get_or_create
with transaction.atomic(using=self.db):
File "/usr/local/alwaysdata/python/django/1.6.1/django/db/transaction.py", lin
e 277, in __enter__
connection._start_transaction_under_autocommit()
File "/usr/local/alwaysdata/python/django/1.6.1/django/db/backends/sqlite3/bas
e.py", line 436, in _start_transaction_under_autocommit
self.cursor().execute("BEGIN")
File "/usr/local/alwaysdata/python/django/1.6.1/django/db/backends/util.py", l
ine 69, in execute
return super(CursorDebugWrapper, self).execute(sql, params)
File "/usr/local/alwaysdata/python/django/1.6.1/django/db/backends/util.py", l
ine 53, in execute
return self.cursor.execute(sql, params)
File "/usr/local/alwaysdata/python/django/1.6.1/django/db/utils.py", line 99,
in __exit__
six.reraise(dj_exc_type, dj_exc_value, traceback)
File "/usr/local/alwaysdata/python/django/1.6.1/django/db/backends/util.py", l
ine 51, in execute
return self.cursor.execute(sql)
File "/usr/local/alwaysdata/python/django/1.6.1/django/db/backends/sqlite3/bas
e.py", line 448, in execute
return Database.Cursor.execute(self, query)
django.db.utils.OperationalError: cannot start a transaction within a transaction
My settings my include:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': 'database.db',
}
}
I don't know how to solve this problem. Could someone help me, please?
I assume you are using the hosting service of Alwaysdata because I Googled this problem and here is the same question on Alwaysdata's forum: Django sqlite3 - an error when manage.py syncdb.
The way I solve this problem is switching to a lower version of Django (e.g. 1.5.5) in my Alwaysdata admin page. Then the db file can be created successfully.
I still have not got the reason why this happens.
So, I am learning to use South and I've been running in a few issues. I did the initial app migration with the model looking like this:
class Poll(models.Model):
pass
Then added my fields...
class Poll(models.Model):
question = models.CharField(max_length=200)
pub_date = models.DateTimeField()
and during the migration South complained that those fields didn't have a default, so I entered some but it didn't work... now when I try deleting them from the model and migrating back to the empty mode I get the following traceback:
mirkocrocop#Mirkos-MacBook-Pro:~/workspace/toastdriven$ python manage.py migrate polls
Running migrations for polls:
- Migrating forwards to 0007_auto__del_field_poll_question.
> polls:0003_auto__add_field_poll_question__add_field_poll_pub_date
Traceback (most recent call last):
File "manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "/Users/mirkocrocop/.virtualenvs/toastdriven/lib/python2.7/site-packages/django/core/management/__init__.py", line 443, in execute_from_command_line
utility.execute()
File "/Users/mirkocrocop/.virtualenvs/toastdriven/lib/python2.7/site-packages/django/core/management/__init__.py", line 382, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/Users/mirkocrocop/.virtualenvs/toastdriven/lib/python2.7/site-packages/django/core/management/base.py", line 196, in run_from_argv
self.execute(*args, **options.__dict__)
File "/Users/mirkocrocop/.virtualenvs/toastdriven/lib/python2.7/site-packages/django/core/management/base.py", line 232, in execute
output = self.handle(*args, **options)
File "/Users/mirkocrocop/.virtualenvs/toastdriven/lib/python2.7/site-packages/south/management/commands/migrate.py", line 108, in handle
ignore_ghosts = ignore_ghosts,
File "/Users/mirkocrocop/.virtualenvs/toastdriven/lib/python2.7/site-packages/south/migration/__init__.py", line 213, in migrate_app
success = migrator.migrate_many(target, workplan, database)
File "/Users/mirkocrocop/.virtualenvs/toastdriven/lib/python2.7/site-packages/south/migration/migrators.py", line 235, in migrate_many
result = migrator.__class__.migrate_many(migrator, target, migrations, database)
File "/Users/mirkocrocop/.virtualenvs/toastdriven/lib/python2.7/site-packages/south/migration/migrators.py", line 310, in migrate_many
result = self.migrate(migration, database)
File "/Users/mirkocrocop/.virtualenvs/toastdriven/lib/python2.7/site-packages/south/migration/migrators.py", line 133, in migrate
result = self.run(migration)
File "/Users/mirkocrocop/.virtualenvs/toastdriven/lib/python2.7/site-packages/south/migration/migrators.py", line 106, in run
dry_run.run_migration(migration)
File "/Users/mirkocrocop/.virtualenvs/toastdriven/lib/python2.7/site-packages/south/migration/migrators.py", line 191, in run_migration
self._run_migration(migration)
File "/Users/mirkocrocop/.virtualenvs/toastdriven/lib/python2.7/site-packages/south/migration/migrators.py", line 178, in _run_migration
raise exceptions.FailedDryRun(migration, sys.exc_info())
south.exceptions.FailedDryRun: ! Error found during dry run of '0003_auto__add_field_poll_question__add_field_poll_pub_date'! Aborting.
Traceback (most recent call last):
File "/Users/mirkocrocop/.virtualenvs/toastdriven/lib/python2.7/site-packages/south/migration/migrators.py", line 175, in _run_migration
migration_function()
File "/Users/mirkocrocop/.virtualenvs/toastdriven/lib/python2.7/site-packages/south/migration/migrators.py", line 57, in <lambda>
return (lambda: direction(orm))
File "/Users/mirkocrocop/workspace/toastdriven/polls/migrations/0003_auto__add_field_poll_question__add_field_poll_pub_date.py", line 19, in forwards
keep_default=False)
File "/Users/mirkocrocop/.virtualenvs/toastdriven/lib/python2.7/site-packages/south/db/sqlite3.py", line 31, in add_column
field.column: self._column_sql_for_create(table_name, name, field, False),
File "/Users/mirkocrocop/.virtualenvs/toastdriven/lib/python2.7/site-packages/south/db/sqlite3.py", line 189, in _column_sql_for_create
sql = self.column_sql(table_name, name, field, with_name=False, field_prepared=True)
File "/Users/mirkocrocop/.virtualenvs/toastdriven/lib/python2.7/site-packages/south/db/generic.py", line 688, in column_sql
default = field.get_db_prep_save(default, connection=self._get_connection())
File "/Users/mirkocrocop/.virtualenvs/toastdriven/lib/python2.7/site-packages/django/db/models/fields/__init__.py", line 292, in get_db_prep_save
prepared=False)
File "/Users/mirkocrocop/.virtualenvs/toastdriven/lib/python2.7/site-packages/django/db/models/fields/__init__.py", line 816, in get_db_prep_value
value = self.get_prep_value(value)
File "/Users/mirkocrocop/.virtualenvs/toastdriven/lib/python2.7/site-packages/django/db/models/fields/__init__.py", line 801, in get_prep_value
value = self.to_python(value)
File "/Users/mirkocrocop/.virtualenvs/toastdriven/lib/python2.7/site-packages/django/db/models/fields/__init__.py", line 785, in to_python
raise exceptions.ValidationError(msg)
ValidationError: [u"'0' value has an invalid format. It must be in YYYY-MM-DD HH:MM[:ss[.uuuuuu]][TZ] format."]
How could I fix this, and what is the correct way of adding these fields + doing the migration from the empty model to the field populated model? I've been going through South's docs but I don't get it... I did everything according to the documentation, but I'm not sure what should I default the DateTimeField to...
At the time you have to provide a default value, you are interacting with a python interpreter. As it is mentioned, the datetime module is available at that point in time. To provide a default for a DateTimeField in this case, just provide a datetime object:
# Use the current date and time
datetime.datetime.now()
# Or a specific date and time
datetime.datetime(2012, 10, 1, 17, 30, 0, 0)
I am deploying my django project using amazon ec2 and the bitnami-djangostack ami.
While I was developing the app locally I used mysql. But after deploying the project I used the default for bitnami postgresql.
Now I am getting the following error:
django.db.utils.DatabaseError: relation "appName_appName" does not exist
LINE 1: SELECT (1) AS "a" FROM "appName_appName" WHERE "appName_a...
^
I don't know why the database is naming the database twice (appName_appName).
here is the full terminal:
bitnami#dom:/opt/bitnami/projects/Project$ sudo python manage.py syncdb
/opt/bitnami/apps/django/lib/python2.6/site-packages/django/db/__init__.py:60: DeprecationWarning: Short names for ENGINE in database configurations are deprecated. Prepend default.ENGINE with 'django.db.backends.'
DeprecationWarning
/opt/bitnami/projects/Project/cookbook/models.py:94: DeprecationWarning: A Field class whose db_type method hasn't been updated to take a `connection` argument.
class JSONField(models.TextField):
Syncing...
Creating tables ...
Creating table auth_permission
Creating table auth_group_permissions
Creating table auth_group
Creating table auth_user_user_permissions
Creating table auth_user_groups
Creating table auth_user
Creating table auth_message
Creating table django_content_type
Creating table django_session
Creating table django_site
Creating table django_admin_log
Creating table registration_registrationprofile
Creating table south_migrationhistory
You just installed Django's auth system, which means you don't have any superusers defined.
Would you like to create one now? (yes/no): yesa
Please enter either "yes" or "no": yes
Username (Leave blank to use 'root'): xxxx
E-mail address: xxxxx
Password: xxx
Password (again): xxx
Traceback (most recent call last):
File "manage.py", line 14, in <module>
execute_manager(settings)
File "/opt/bitnami/apps/django/lib/python2.6/site-packages/django/core/management/__init__.py", line 438, in execute_manager
utility.execute()
File "/opt/bitnami/apps/django/lib/python2.6/site-packages/django/core/management/__init__.py", line 379, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/opt/bitnami/apps/django/lib/python2.6/site-packages/django/core/management/base.py", line 191, in run_from_argv
self.execute(*args, **options.__dict__)
File "/opt/bitnami/apps/django/lib/python2.6/site-packages/django/core/management/base.py", line 220, in execute
output = self.handle(*args, **options)
File "/opt/bitnami/apps/django/lib/python2.6/site-packages/django/core/management/base.py", line 351, in handle
return self.handle_noargs(**options)
File "/opt/bitnami/python/lib/python2.6/site-packages/South-0.7.6-py2.6.egg/south/management/commands/syncdb.py", line 90, in handle_noargs
syncdb.Command().execute(**options)
File "/opt/bitnami/apps/django/lib/python2.6/site-packages/django/core/management/base.py", line 220, in execute
output = self.handle(*args, **options)
File "/opt/bitnami/apps/django/lib/python2.6/site-packages/django/core/management/base.py", line 351, in handle
return self.handle_noargs(**options)
File "/opt/bitnami/apps/django/lib/python2.6/site-packages/django/core/management/commands/syncdb.py", line 109, in handle_noargs
emit_post_sync_signal(created_models, verbosity, interactive, db)
File "/opt/bitnami/apps/django/lib/python2.6/site-packages/django/core/management/sql.py", line 190, in emit_post_sync_signal
interactive=interactive, db=db)
File "/opt/bitnami/apps/django/lib/python2.6/site-packages/django/dispatch/dispatcher.py", line 172, in send
response = receiver(signal=self, sender=sender, **named)
File "/opt/bitnami/apps/django/lib/python2.6/site-packages/django/contrib/auth/management/__init__.py", line 70, in create_superuser
call_command("createsuperuser", interactive=True)
File "/opt/bitnami/apps/django/lib/python2.6/site-packages/django/core/management/__init__.py", line 166, in call_command
return klass.execute(*args, **defaults)
File "/opt/bitnami/apps/django/lib/python2.6/site-packages/django/core/management/base.py", line 220, in execute
output = self.handle(*args, **options)
File "/opt/bitnami/apps/django/lib/python2.6/site-packages/django/contrib/auth/management/commands/createsuperuser.py", line 134, in handle
User.objects.create_superuser(username, email, password)
File "/opt/bitnami/apps/django/lib/python2.6/site-packages/django/contrib/auth/models.py", line 140, in create_superuser
u = self.create_user(username, email, password)
File "/opt/bitnami/apps/django/lib/python2.6/site-packages/django/contrib/auth/models.py", line 136, in create_user
user.save(using=self._db)
File "/opt/bitnami/apps/django/lib/python2.6/site-packages/django/db/models/base.py", line 460, in save
self.save_base(using=using, force_insert=force_insert, force_update=force_update)
File "/opt/bitnami/apps/django/lib/python2.6/site-packages/django/db/models/base.py", line 570, in save_base
created=(not record_exists), raw=raw, using=using)
File "/opt/bitnami/apps/django/lib/python2.6/site-packages/django/dispatch/dispatcher.py", line 172, in send
response = receiver(signal=self, sender=sender, **named)
File "/opt/bitnami/projects/Project/cookbook/models.py", line 68, in create_cookbook_for_user
if created and not instance.cookbooks.exists():
File "/opt/bitnami/apps/django/lib/python2.6/site-packages/django/db/models/manager.py", line 192, in exists
return self.get_query_set().exists(*args, **kwargs)
File "/opt/bitnami/apps/django/lib/python2.6/site-packages/django/db/models/query.py", line 496, in exists
return self.query.has_results(using=self.db)
File "/opt/bitnami/apps/django/lib/python2.6/site-packages/django/db/models/sql/query.py", line 424, in has_results
return bool(compiler.execute_sql(SINGLE))
File "/opt/bitnami/apps/django/lib/python2.6/site-packages/django/db/models/sql/compiler.py", line 735, in execute_sql
cursor.execute(sql, params)
File "/opt/bitnami/apps/django/lib/python2.6/site-packages/django/db/backends/util.py", line 34, in execute
return self.cursor.execute(sql, params)
File "/opt/bitnami/apps/django/lib/python2.6/site-packages/django/db/backends/postgresql_psycopg2/base.py", line 44, in execute
return self.cursor.execute(query, args)
django.db.utils.DatabaseError: relation "appName_appName" does not exist
LINE 1: SELECT (1) AS "a" FROM "appName_appName" WHERE "appName_a...
^
thank you,
katie
I just added the appname_appname to my database and it now works fine.
sorry to mislead - my mistake. I still don't understand why the piece of code wasn't being added to the database on syncdb to begin with though.
but all is well now