Modify

Ticket #641 (closed defect: fixed)

Opened 4 years ago

Last modified 3 years ago

Fixture installing doesn't recognize "--database" option

Reported by: dolan@… Owned by: andrew
Priority: major Milestone: 0.7.3
Component: migrations Version: 0.7.1
Keywords: Cc:

Description

When migrating a module with fixtures, and using the --database option, fixture installation uses the default connection instead of the connection specified by --database. The module will migrate using the specified database, but not the fixtures.

Example:
./manage.py migrate mymodule --database=master

I haven't tried 0.7.2, so if this is already fixed (or reported), my apologies for duplicating.

Attachments

Change History

comment:1 Changed 4 years ago by andrew

  • Status changed from new to closed
  • Resolution set to duplicate
  • Milestone set to 0.7.3

This is either a duplicate of #469, or something you'll have to fix manually if you're using call_command in your migration code (the current database alias is available as db.db_alias).

comment:2 Changed 3 years ago by dolan@…

  • Status changed from closed to reopened
  • Resolution duplicate deleted

This appears to still be an issue in 0.7.3. I am not using call_command, but simply "manage.py migrate", and when it gets to an application that has a "fixtures" directory in itself, it attempts to run that, but does so on the "default" connection.

Running migrations for myapp:
- Nothing to migrate.
 - Loading initial data for myapp.
Installing json fixture 'initial_data' from '/home/user/myproject/apps/myapp/fixtures'.
Problem installing fixture '/home/user/myproject/apps/myapp/fixtures/initial_data.json': Traceback (most recent call last):
  File "/home/user/myproject/apps/django/core/management/commands/loaddata.py", line 174, in handle
    obj.save(using=using)
  File "//home/user/myproject/apps/django/core/serializers/base.py", line 165, in save
    models.Model.save_base(self.object, using=using, raw=True)
  File "/home/user/myproject/apps/django/db/models/base.py", line 522, in save_base
    rows = manager.using(using).filter(pk=pk_val)._update(values)
  File "/home/user/myproject/apps/django/db/models/query.py", line 497, in _update
    return query.get_compiler(self.db).execute_sql(None)
  File "/home/user/myproject/apps/django/db/models/sql/compiler.py", line 866, in execute_sql
    cursor = super(SQLUpdateCompiler, self).execute_sql(result_type)
  File "/home/user/myproject/apps/django/db/models/sql/compiler.py", line 732, in execute_sql
    cursor.execute(sql, params)
  File "/home/user/myproject/apps/django/db/backends/util.py", line 15, in execute
    return self.cursor.execute(sql, params)
  File "/home/user/myproject/apps/django/db/backends/mysql/base.py", line 86, in execute
    return self.cursor.execute(query, args)
  File "/usr/lib/pymodules/python2.6/MySQLdb/cursors.py", line 166, in execute
    self.errorhandler(self, exc, value)
  File "/usr/lib/pymodules/python2.6/MySQLdb/connections.py", line 35, in defaulterrorhandler
    raise errorclass, errorvalue
OperationalError: (1142, "UPDATE command denied to user 'readuser'@'localhost' for table 'myapp_somemodel'")

comment:3 Changed 3 years ago by dolan@…

I fixed this on BitBucket?, and issued a Pull Request (user: pydolan). FYI

comment:4 Changed 3 years ago by andrew

  • Status changed from reopened to closed
  • Resolution set to fixed

Thanks for that, I've pulled the change.

View

Add a comment

Modify Ticket

Action
as closed
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.