1

The table design is,

Table A:
    - ID - Type Int - Primary Key

Table B:
    - ForeignKey(A)

How can I use south to change the type of ID in table A from Int to BigInt ?

Edited: I tried the following and it did not work.

  • Alter the ID type to BigInt

    db.alter_column('A', 'ID', models.BigIntegerField(primary_key = True))
    

Error : DatabaseError: (1025, "Error on rename of './app/#sql-d7_3f8' to './app/A' (errno: 150 - Foreign key constraint is incorrectly formed)")

  • Deleting the PK, so that it can be recreated again

    db.delete_primary_key('A')
    

Error: DatabaseError: (1075, 'Incorrect table definition; there can be only one auto column and it must be defined as a key')

NEB
  • 712
  • 9
  • 25
  • I am not sure, are you using [south](http://south.readthedocs.org/en/latest/) ?? – ruddra Jul 09 '14 at 09:08
  • I'm pretty sure that I'm using [south](http://south.readthedocs.org/en/latest/). I got some inputs form [Does Django's south (migration tool) work for innodb?](http://stackoverflow.com/questions/4834415/does-djangos-south-migration-tool-work-for-innodb). Will try around the same. – NEB Jul 09 '14 at 10:18

1 Answers1

-1

Make the required changes and then do the following:

python manage.py schemamigration your_app_name --auto

Then finally do:

python manage.py syncdb --migrate
gmfreak
  • 399
  • 4
  • 12
  • This is what I've been doing. But the 'auto'(at-least for my case) will only generate the change from 'Int' to 'BigInt' (in table A) and will not take care for any FKs referring to them (in table B). Also one more issue is, as mentioned in the [post](http://stackoverflow.com/a/7919609/1879604). So, I need to delete / disable the check for the FKs, and update the filed form 'Int' to 'BigInt' (in table A) and also update all the FK ('Int' to 'BigInt') reference in different tables (in table B). – NEB Jul 09 '14 at 10:31
  • Have a look at this question: http://stackoverflow.com/questions/2055784/what-is-the-best-approach-to-change-primary-keys-in-an-existing-django-app – gmfreak Jul 09 '14 at 10:35