gpt4 book ai didi

database - Grails 一直在删除我的表

转载 作者:搜寻专家 更新时间:2023-10-30 19:54:39 25 4
gpt4 key购买 nike

我的表结构如下:

CREATE TABLE test_two_tabel.T1 ( T1_ID INT NOT NULL AUTO_INCREMENT , A1 INT NULL , B1 VARCHAR(45) NULL , C1 VARCHAR(45) NULL , D1 DATETIME NULL , PRIMARY KEY (T1_ID) );

在 Grails 中:

package twotables

class T1 {

Integer a
String b
String c
Date d

static mapping = {
table "T1"
version false
id column:"T1_ID"
a1 column:"a1"
b1 column:"b1"
c1 column:"c1"
d1 column:"d1"
}

static constraints = {
id()
a1()
b1()
c1()
d1()
}
}

每次我执行我的程序时...Grails 都会删除我在数据库中的表,有人知道发生了什么吗?

最佳答案

您需要在 grails-app/conf/DataSource.groovy 中将 dbCreate 的值从 'create-drop' 更改为 'update'

您当前的值可能是:

development {
dataSource {
dbCreate = "create-drop" // one of 'create', 'create-drop','update'
url = "***"
}
}

这意味着 Grails 将在每次重启时重新创建所有表。如果您将其设置为 update,它将根据您的数据模型类尝试更新表结构。

您可以在 http://www.grails.org/doc/latest/guide/3.%20Configuration.html#3.3%20The%20DataSource 阅读有关 Grails 数据库配置的更多信息

关于database - Grails 一直在删除我的表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6548663/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com