Open viyonBox opened 1 week ago
The issue has been automatically marked as stale as it missing playground pull request link, which is important to help others understand your issue effectively and make sure the issue hasn't been fixed on latest master, checkout https://github.com/go-gorm/playground for details. it will be closed in 30 days if no further activity occurs. if you are asking question, please use the Question
template, most likely your question already answered https://github.com/go-gorm/gorm/issues or described in the document https://gorm.io ✨ Search Before Asking ✨
There is no column named please
.
Your defined struct with name TbLevels
, and the created table by sql with table name tb_levels
, none of them has a column named please
, just exactly what the error shows up.
Why don't you read the error more carefully?
The issue has been automatically marked as stale as it missing playground pull request link, which is important to help others understand your issue effectively and make sure the issue hasn't been fixed on latest master, checkout https://github.com/go-gorm/playground for details. it will be closed in 30 days if no further activity occurs. if you are asking question, please use the Question
template, most likely your question already answered https://github.com/go-gorm/gorm/issues or described in the document https://gorm.io ✨ Search Before Asking ✨
There is no column named
please
. Your defined struct with nameTbLevels
, and the created table by sql with table nametb_levels
, none of them has a column namedplease
, just exactly what the error shows up.Why don't you read the error more carefully?
原始的数据库建表语句中本身就没有please这一列。我的理解是AutoMigrate内部在解析数据库建表语句的时候,用的逗号分割的schema,导致把please误认为是一个column,而实际上不是。
如果建表语句是下面这样
CREATE TABLE tb_levels (
level_id INTEGER NOT NULL,
name TEXT NOT NULL,
code INTEGER NOT NULL,
source INTEGER NULL DEFAULT 1
);
AutoMigrate函数是可以迁移成功的。
The issue has been automatically marked as stale as it missing playground pull request link, which is important to help others understand your issue effectively and make sure the issue hasn't been fixed on latest master, checkout https://github.com/go-gorm/playground for details. it will be closed in 30 days if no further activity occurs. if you are asking question, please use the Question
template, most likely your question already answered https://github.com/go-gorm/gorm/issues or described in the document https://gorm.io ✨ Search Before Asking ✨
GORM Playground Link
https://github.com/go-gorm/gorm/releases/tag/v1.25.12
Description
1.已经存在了一个sqlite3数据库,表结构已经通过sql语句被建立好了,建表语句如下:
生成一个a.db的sqlite数据库文件。
2.使用AutoMigrate函数修改表结构,go代码程序如下:
go build 生成gormtest程序 3.运行gormtest程序,报错如下 ./gormtest
2024/11/12 11:41:54 table tb_levels__temp has no column named please [0.017ms] [rows:0] INSERT INTO
tb_levels__temp
(please
,code
,0
) SELECTplease
,code
,0
FROMtb_levels
Failed to auto migrate database, error is table tb_levels__temp has no column named please, retry.