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

AutoMigrate keeps receating tables if model has unique composite indexes #643

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

IrineSistiana
Copy link

Explain your user case and expected results

这是一个极简复现。

test 不会 failed。但可以从 log 中看出表被重建了多次。

2023/08/23 19:34:30 main_test.go:31
[0.000ms] [rows:-] SELECT count(*) FROM sqlite_master WHERE type='table' AND name="ms"

2023/08/23 19:34:30 main_test.go:31
[0.000ms] [rows:2] SELECT sql FROM sqlite_master WHERE type IN ("table","index") AND tbl_name = "ms" AND sql IS NOT NULL order by type = "table" desc

2023/08/23 19:34:30 main_test.go:31
[0.000ms] [rows:-] SELECT * FROM `ms` LIMIT 1

2023/08/23 19:34:30 main_test.go:31
[0.554ms] [rows:1] PRAGMA foreign_keys

2023/08/23 19:34:30 
[0.000ms] [rows:-] SELECT sql FROM sqlite_master WHERE type = "table" AND tbl_name = "ms" AND name = "ms"

2023/08/23 19:34:30 
[0.590ms] [rows:0] CREATE TABLE `ms__temp` (`id` integer,`i` text,`i2` text,PRIMARY KEY (`id`))

2023/08/23 19:34:30 
[0.000ms] [rows:0] INSERT INTO `ms__temp`(`id`,`i`,`i2`) SELECT `id`,`i`,`i2` FROM `ms`

2023/08/23 19:34:30 
[0.610ms] [rows:0] DROP TABLE `ms`

2023/08/23 19:34:30 
[2.264ms] [rows:0] ALTER TABLE `ms__temp` RENAME TO `ms`

2023/08/23 19:34:30 main_test.go:31
[0.000ms] [rows:1] PRAGMA foreign_keys

2023/08/23 19:34:30 
[0.000ms] [rows:-] SELECT sql FROM sqlite_master WHERE type = "table" AND tbl_name = "ms" AND name = "ms"

2023/08/23 19:34:30 
[0.000ms] [rows:0] CREATE TABLE `ms__temp` (`id` integer,`i` text,`i2` text,PRIMARY KEY (`id`))

2023/08/23 19:34:30 
[0.000ms] [rows:0] INSERT INTO `ms__temp`(`id`,`i`,`i2`) SELECT `id`,`i`,`i2` FROM `ms`

2023/08/23 19:34:30 
[0.539ms] [rows:0] DROP TABLE `ms`

2023/08/23 19:34:30 
[1.057ms] [rows:0] ALTER TABLE `ms__temp` RENAME TO `ms`

2023/08/23 19:34:30 main_test.go:31
[0.000ms] [rows:-] SELECT count(*) FROM sqlite_master WHERE type = "index" AND tbl_name = "ms" AND name = "idx_name"

2023/08/23 19:34:30 main_test.go:31
[0.000ms] [rows:0] CREATE UNIQUE INDEX `idx_name` ON `ms`(`i`,`i2`)
PASS
Process 23596 has exited with status 0
Detaching
dlv dap (26924) exited with code: 0

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

Successfully merging this pull request may close these issues.

1 participant