mysql - How to update case of field with FK constraint to it -


i looking standardize fields in database. how following, field has fk constraint it:

in django:

platform.objects.filter(name='itunes').update(name='itunes') # gives fk error 

in mysql:

update main_platform set name='itunes' name='itunes' # cannot delete or update parent row: foreign key constraint fails (`avails`.`main_credit`, constraint `main_credit_ibfk_3` foreign key (`platform_id`) references `main_platform` (`name`)) 

what solution this?

please note i'm not looking add additional fields, such id field, fk never change, i'm interested in updating existing field.

the current table have platform is:

create table `main_platform` (   `name` varchar(20) not null,   `guid` varchar(40) default null,   primary key (`name`),   key `guid` (`guid`) ) engine=innodb default charset=utf8; 

this looks more of sql problem anything.

you have name primary key, if try update directly when there rows in linked tables referencing it, things going break.

if you're not going modify table use numeric id primary key (which idea), best real option have can see add new row main_platform new name field (itunes vs itunes), migrate related data point new row, , delete old row.

see this answer more insight problem, , persuaded , and use numeric id primary key.


Comments

Popular posts from this blog

yii2 - Yii 2 Running a Cron in the basic template -

asp.net - 'System.Web.HttpContext' does not contain a definition for 'GetOwinContext' Mystery -

mercurial graft feature, can it copy? -