﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
18652	loaddata --database option ignored	dack@…	nobody	"When using the manage.py loaddata command, the --database option appears to be silently ignored. Instead of applying to the specified database, it applies to the default database.

Example follows:

== settings.py ==
{{{
DATABASES = {
  'mysql': {
  'ENGINE': 'django.db.backends.mysql',
  'NAME': 'django',
  'USER': 'django',
  'PASSWORD': 'XXXXXXXXXXXX',
  'HOST': '',
  'PORT': '',
  },
  'default': {
    'ENGINE': 'django.db.backends.sqlite3',
    'NAME': '/foo.db',
  }
}
}}}
== commands used ==

>foo.db contains some data.
'''./manage.py flush --database=mysql'''
{{{
You have requested a flush of the database.
This will IRREVERSIBLY DESTROY all data currently in the 'django' database,
and return each table to the state it was in after syncdb.
Are you sure you want to do this?

    Type 'yes' to continue, or 'no' to cancel: yes

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): no
Installed 0 object(s) from 0 fixture(s)
}}}
>mysql database inspected - verified it contains no data at this point
'''./manage.py dumpdata -a -n > data.json'''
>data.json inspected - contains sample data from the default database (foo.db)
'''./manage.py loaddata --database=mysql ./data.json'''
{{{
Problem installing fixture './data.json': Traceback (most recent call last):
  File ""/usr/local/lib/python2.6/site-packages/django/core/management/commands/loaddata.py"", line 196, in handle
    obj.save(using=using)
  File ""/usr/local/lib/python2.6/site-packages/django/core/serializers/base.py"", line 165, in save
    models.Model.save_base(self.object, using=using, raw=True)
  File ""/usr/local/lib/python2.6/site-packages/django/db/models/base.py"", line 565, in save_base
    created=(not record_exists), raw=raw, using=using)
  File ""/usr/local/lib/python2.6/site-packages/django/dispatch/dispatcher.py"", line 172, in send
    response = receiver(signal=self, sender=sender, **named)
  File ""/genpool0/db/foo/intranet/../intranet/userprofile/models.py"", line 22, in create_user_profile
    UserProfile.objects.create(user=instance)
  File ""/usr/local/lib/python2.6/site-packages/django/db/models/manager.py"", line 137, in create
    return self.get_query_set().create(**kwargs)
  File ""/usr/local/lib/python2.6/site-packages/django/db/models/query.py"", line 377, in create
    obj.save(force_insert=True, using=self.db)
  File ""/usr/local/lib/python2.6/site-packages/django/db/models/base.py"", line 463, in save
    self.save_base(using=using, force_insert=force_insert, force_update=force_update)
  File ""/usr/local/lib/python2.6/site-packages/django/db/models/base.py"", line 551, in save_base
    result = manager._insert([self], fields=fields, return_id=update_pk, using=using, raw=raw)
  File ""/usr/local/lib/python2.6/site-packages/django/db/models/manager.py"", line 203, in _insert
    return insert_query(self.model, objs, fields, **kwargs)
  File ""/usr/local/lib/python2.6/site-packages/django/db/models/query.py"", line 1576, in insert_query
    return query.get_compiler(using=using).execute_sql(return_id)
  File ""/usr/local/lib/python2.6/site-packages/django/db/models/sql/compiler.py"", line 910, in execute_sql
    cursor.execute(sql, params)
  File ""/usr/local/lib/python2.6/site-packages/django/db/backends/util.py"", line 40, in execute
    return self.cursor.execute(sql, params)
  File ""/usr/local/lib/python2.6/site-packages/django/db/backends/sqlite3/base.py"", line 337, in execute
    return Database.Cursor.execute(self, query, params)
IntegrityError: Could not load auth.User(pk=1): column user_id is not unique
}}}
>note the 3rd to last line of the traceback. it's using sqlite3 backend instead of mysql.
>let's try flushing the default database
'''./manage.py flush'''
{{{
You have requested a flush of the database.
This will IRREVERSIBLY DESTROY all data currently in the '/genpool0/db/foo/foo.db' database,
and return each table to the state it was in after syncdb.
Are you sure you want to do this?

    Type 'yes' to continue, or 'no' to cancel: yes

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): no
Installed 0 object(s) from 0 fixture(s)
}}}
>and try the same command that failed before
'''./manage.py loaddata --database=mysql ./data.json'''
{{{
Installed 1570 object(s) from 1 fixture(s)
}}}
>the data was installed back into the default database, instead of the mysql database"	Bug	closed	Core (Management commands)	1.4	Normal	invalid	loaddata --database manage.py		Unreviewed	0	0	0	0	0	0
