异常信息: a unique database constraint for 2 or more fields together 场景描述: 对于ORM中多对多关系的中间表,如果该关系表是手动创建的,建表的时候,两个字段没有添加联合唯一约束: 系统运行一段时间后,若是需求变更,需要对其增加联合唯一约束,而当前的关系表中可能已存在重复数据了,那么在添加联合唯一约束,执行数据同步操作migrate的时候,就会报错:这时,可以参考这种处理方式. 推荐一篇博客:http://shineforever.b
表结构 FIELD TYPE COLLATION NULL KEY DEFAULT Extra PRIVILEGES COMMENT ------------- ------------ -------------- ------ ------ ------- -------------- -------------------- ------- id
6个字段组成联合唯一索引 索引名称code_level_metric_type_week_year sql语句联合索引 CREATE UNIQUE INDEX code_level_metric_type_week_year ON dept_utilization (dept_code,dept_level,metric,statistical_type,week_of_year,year);
首先导包: import uuid uuid1(): # make a UUID based on the host ID and current time # 基于MAC地址,时间戳,随机数来生成唯一的uuid,可以保证全球范围内的唯一性 >>> uuid.uuid1() # doctest: +SKIP 结果:UUID('a8098c1a-f86e-11da-bd1a-00112444be1e') uuid3(): # make a UUID using an