Ticket #266 (closed defect: fixed)

Opened 5 months ago

Last modified 3 weeks ago

rename_column does not specify table name

Reported by: anonymous Owned by: andrew
Priority: major Milestone: 0.7
Component: commands Version: 0.6
Keywords: Cc:

Description

I renamed a model field from a foreign key to a varchar using:

./manage.py startmigration <app> change_field --auto

When running the migration with:

./manage.py migrate <app>

I got the following error:

db.alter_column('greek_letter', ormfrat.lineentity:greek_letter?)

TypeError?: alter_column() takes at least 4 arguments (3 given)

Going into the migration and adding the table name as the first argument fixes the problem.

When running the migration backwards, I get the following error:

psycopg2.ProgrammingError?: column "greek_letter" cannot be cast to type "pg_catalog.int4"

In order to do the reverse migration I delete the column and create a new one altogether.

I am running south against PostgresSQL using psycopg2.

Attachments

Change History

Changed 5 months ago by andrew

  • status changed from new to assigned
  • milestone set to 0.6.2

This is very odd; is there any chance of seeing the before/after models which caused this? Does it happen again if you try in the same situation?

Also, the error you get on backwards() is because you altered an integer column to a text one (most likely), which postgres considers an irreversible operation.

Changed 5 months ago by andrew

  • milestone changed from 0.6.2 to 0.6.3

Changed 5 months ago by preston@…

Just a note that I hit this bug too.

Went from a varchar to a FK column

--auto didn't generate a table name:

# Renaming column for field 'country'.
db.rename_column('country', 'country_id')

Changed 4 months ago by flashingpumpkin@…

I've gotta second that. Went from varchar to ForeignKey? too and got the same hiccup.

The db backend used is MySQL

(pp)alen@fp:[pp]$ python manage.py startmigration pa profile --auto
 + Added model 'pa.referrercode'
 ~ Changed field 'pa.profile.referrer_code'.
Created 0005_profile.py.

(pp)alen@fp:[pp]$ python manage.py migrate pa
Running migrations for pa:
 - Migrating forwards to 0005_profile.
 > pa: 0005_profile
Traceback (most recent call last):
  File "/home/alen/projects/pp/lib/python2.6/site-packages/south/migration.py", line 307, in run_migrations
    runfunc(orm)
  File "/home/alen/projects/pp/src/pa/pa/migrations/0005_profile.py", line 18, in forwards
    db.rename_column('referrer_code', 'referrer_code_id')
TypeError: rename_column() takes exactly 4 arguments (3 given)
 ! Error found during dry run of migration! Aborting.

Changed 4 months ago by andrew

Could one of you post the models.py file that's making this happen? (pref. before and after), and the migration?

Changed 4 months ago by anonymous

Andrew - I was just able to reproduce this with a copy of my code.

The change was going from line 11 (commented out) to line 12 in this paste:
http://dpaste.com/118138/

The Country class is coming from django-countries

-Preston

Changed 4 months ago by anonymous

The models.py and the pre and post FK change migrations from my test:

http://ptone.com/temp/migrations_issue.zip

-Preston

Changed 4 months ago by ed@…

My situtation was going from a PositiveSmallIntegerField? to a FK. Same symptoms.

Changed 3 months ago by epottercg@…

Any progress on this?

Changed 3 weeks ago by andrew

  • status changed from assigned to closed
  • resolution set to fixed
  • milestone changed from 0.6.3 to 0.7

Fixed in 0.7.

Add/Change #266 (rename_column does not specify table name)

Author



Action
as closed
Next status will be 'reopened'
 
Note: See TracTickets for help on using tickets.