Opened 8 years ago

Closed 8 years ago

#23540 closed Uncategorized (duplicate)

RunSQL Bug Django 1.7

Reported by: Aryeh Hillman Owned by: nobody
Component: Migrations Version: 1.7
Severity: Normal Keywords: migrations runsql postgresql
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no


Django migrations are wonderful, but I have found a bug. Here's how to reproduce (there is probably a more minimal case):

  1. Install this function at a shell for PostgreSQL

`CREATE FUNCTION exec(text) returns text language plpgsql volatile

AS $f$






  1. Write a RunSQL operation to help rename some tables

`class Migration(migrations.Migration):

operations = [




sql="""select exec(format('alter table %I rename to %I', tablename, regexp_replace(tablename, 'hello, 'goodbye'))) from pg_tables where tablename like 'hello%';"""



  1. Run the migration. I got this error:

`Traceback (most recent call last):

File "./", line 10, in <module>


File "/Users/abhillman/stable_env/lib/python2.7/site-packages/django/core/management/", line 385, in execute_from_command_line


File "/Users/abhillman/stable_env/lib/python2.7/site-packages/django/core/management/", line 377, in execute


File "/Users/abhillman/stable_env/lib/python2.7/site-packages/django/core/management/", line 288, in run_from_argv

self.execute(*args, options.dict)

File "/Users/abhillman/stable_env/lib/python2.7/site-packages/django/core/management/", line 338, in execute

output = self.handle(*args, options)

File "/Users/abhillman/stable_env/lib/python2.7/site-packages/django/core/management/commands/", line 160, in handle

executor.migrate(targets, plan, fake=options.get("fake", False))

File "/Users/abhillman/stable_env/lib/python2.7/site-packages/django/db/migrations/", line 63, in migrate

self.apply_migration(migration, fake=fake)

File "/Users/abhillman/stable_env/lib/python2.7/site-packages/django/db/migrations/", line 97, in apply_migration

migration.apply(project_state, schema_editor)

File "/Users/abhillman/stable_env/lib/python2.7/site-packages/django/db/migrations/", line 107, in apply

operation.database_forwards(self.app_label, schema_editor, project_state, new_state)

File "/Users/abhillman/stable_env/lib/python2.7/site-packages/django/db/migrations/operations/", line 69, in database_forwards


File "/Users/abhillman/stable_env/lib/python2.7/site-packages/django/db/backends/", line 98, in execute

cursor.execute(sql, params)

File "/Users/abhillman/stable_env/lib/python2.7/site-packages/django/db/backends/", line 81, in execute

return super(CursorDebugWrapper, self).execute(sql, params)

File "/Users/abhillman/stable_env/lib/python2.7/site-packages/django/db/backends/", line 65, in execute

return self.cursor.execute(sql, params)

IndexError: list index out of range`

Not sure what's going on here. Could it be the custom function?

Change History (1)

comment:1 Changed 8 years ago by Aryeh Hillman

Resolution: duplicate
Status: newclosed
Note: See TracTickets for help on using tickets.
Back to Top