#Error when migrating: django.db.utils.OperationalError 1832, "Cannot change column"...

34 messages · Page 1 of 1 (latest)

quaint crypt
#

Hi - having a weird problem when running a migration. I'm getting an OperationalError when running migrate:
django.db.utils.OperationalError: (1832, "Cannot change column 'member_id': used in a foreign key constraint 'core_fee_member_id_ddce3d32_fk_core_member_id'")
The migration does not change any of the referenced ID fields in the error. It adds a new model, and changes some fields of an existing model, but nothing else, so I'm super confused why this is happening. Any help appreciated :)

unique chasm
#

if your code is on github, share the URL and I'll see if I can reproduce the problem

quaint crypt
#

hmm, it isn't

#

not really sure how to send a minimum reproducible example because it's a bit messy

unique chasm
#

yep

quaint crypt
#

ok so this is the core_member table:

MariaDB [skmms]> describe core_member;
+---------------------------+----------------------+------+-----+---------+-------+
| Field                     | Type                 | Null | Key | Default | Extra |
+---------------------------+----------------------+------+-----+---------+-------+
| name                      | varchar(100)         | NO   |     | NULL    |       |
| id                        | uuid                 | NO   | PRI | NULL    |       |
| notes                     | longtext             | NO   |     | NULL    |       |
<snip>
+---------------------------+----------------------+------+-----+---------+-------+
18 rows in set (0.003 sec)
#

and here's core_fee:

MariaDB [skmms]> describe core_fee;
+----------------+------------------+------+-----+---------+-------+
| Field          | Type             | Null | Key | Default | Extra |
+----------------+------------------+------+-----+---------+-------+
| id             | uuid             | NO   | PRI | NULL    |       |
| amount         | int(10) unsigned | NO   |     | NULL    |       |
| invoiced       | date             | YES  |     | NULL    |       |
<snip>
| notes          | longtext         | NO   |     | NULL    |       |
| member_id      | uuid             | NO   | MUL | NULL    |       |
| category       | varchar(1)       | NO   |     | NULL    |       |
+----------------+------------------+------+-----+---------+-------+
13 rows in set (0.003 sec)
#

they are both type uuid

#

the reason i'm confused is the error is talking about the foreign key relationship between core_fee_member_id and core_member_id, but they're not involved in this migration at all

#

the error is apparently that the migration is modifying the type of one of them, thus breaking the foreign key relationship, but no idea why/how

unique chasm
#

sorry I can't digest it unless I have all the code

#

if I had the code I'd just poke at it semi-randomly until something occurred to me :-). That's how I do things

quaint crypt
#

alas

#

yeah i prob can't stick this all on github bc it's for a client

#

any hints for solving it though? anything i should watch out for?

unique chasm
#

can't think of anything; I've never run into that particular problem

#

obviously google for that specific error message; but I assume you've already done that

quaint crypt
#

yeah there wasn't really anything unfortunately

#

pondering if I just drop the db or table and try again

unique chasm
#

if you don't have any important data, then it can't hurt to drop and start over

quaint crypt
#

not sure if this is a bug in Django or just me doing something awful to my models

unique chasm
#

once in a while when I'm working quickly and not paying close attention, I'll get some weird error that goes away when I drop the db 🙂

quaint crypt
unique chasm
#

it's very unlikely to be a bug in django

quaint crypt
#

my thoughts too

unique chasm
quaint crypt
#

good idea

#

well ill go try drop the table

#

and if that still doesn't work then the db

#

will report back :)

#

don't want to be having a DenverCoder9 situation

unique chasm
#

love the XKCD reference (which I am ashamed I didn't immediately recognize)

quaint crypt
#

oh yeah btw I fixed it by dropping the database and recreating