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 :)
#Error when migrating: django.db.utils.OperationalError 1832, "Cannot change column"...
34 messages · Page 1 of 1 (latest)
if your code is on github, share the URL and I'll see if I can reproduce the problem
hmm, it isn't
not really sure how to send a minimum reproducible example because it's a bit messy
yep
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
this is the migration
https://dpaste.org/PN9VV
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
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
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?
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
yeah there wasn't really anything unfortunately
pondering if I just drop the db or table and try again
if you don't have any important data, then it can't hurt to drop and start over
not sure if this is a bug in Django or just me doing something awful to my models
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 🙂
true, a bit more worried about prod but that's a problem for when we get to it
it's very unlikely to be a bug in django
my thoughts too
obviously, get a copy of the prod db locally, and try out the migration locally, before deploying
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
love the XKCD reference (which I am ashamed I didn't immediately recognize)
oh yeah btw I fixed it by dropping the database and recreating