Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

从V1.9.1升级到1.10.0版本升级遇到的BUG #2299

Open
pengkang1991 opened this issue Sep 14, 2023 · 2 comments
Open

从V1.9.1升级到1.10.0版本升级遇到的BUG #2299

pengkang1991 opened this issue Sep 14, 2023 · 2 comments

Comments

@pengkang1991
Copy link
Contributor

重现步骤

从V1.9.1升级到1.10.0版本升级遇到的BUG

  1. 执行 python manage.py dbshell < src/init_sql/v1.10.0.sql

报错如下:
ERROR 1553 (HY000) at line 6: Cannot drop index 'instance_account_instance_id_user_host_514c1ac6_uniq': needed in a foreign key constraint

预期外的结果

报错如下:
ERROR 1553 (HY000) at line 6: Cannot drop index 'instance_account_instance_id_user_host_514c1ac6_uniq': needed in a foreign key constraint

日志文本

No response

版本

1.9.1

部署方式

Docker

是否还有其他可以辅助定位问题的信息?比如数据库版本等

No response

@hhyo
Copy link
Owner

hhyo commented Sep 25, 2023

#2179

看起来是唯一索引的变更导致,如果无法直接migrate,自行sql变更也可以

@ghostclearsky
Copy link

ghostclearsky commented Sep 27, 2023

修改sql脚本 src/init_sql/v1.10.0.sql
在删除索引前,先删除外键
-- 删除外键
set @drop_fk_sql=(select concat('alter table instance_account drop foreign key ',constraint_name) from information_schema.table_constraints where constraint_type='foreign key' and table_name = 'instance_account');
prepare stmt from @drop_fk_sql;
execute stmt;
drop prepare stmt;

-- 然后在索引重建后,再重新添加外键
alter table instance_account add constraint fk_account_sql_instance_id foreign key (instance_id) references sql_instance(id);

注意如果脚本已执行过一次,把上面执行过的语句注释掉
重新执行: python manage.py dbshell < src/init_sql/v1.10.0.sql

1695799101285

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants