gpt4 book ai didi

hibernate - Grails错误spi.SqlExceptionHelper- 'field list'中的未知列

转载 作者:行者123 更新时间:2023-12-02 15:59:19 25 4
gpt4 key购买 nike

我有两个Grails域类(表)之间的Foriegn关键关系

class ServiceProvider {

String name
String address
}

class FieldsDetails implements Serializable {


Integer serviceProviderId

}

我删除了不感兴趣的字段。当我在 FieldsDetails 域类上执行任何方法时,出现以下错误
ERROR spi.SqlExceptionHelper  - Unknown column 'this_.service_provider_id' in 'field list'

数据源条目
development {
dataSource {
//dbCreate = "create-drop" // one of 'create', 'create-drop', 'update', 'validate', ''
//url = "jdbc:h2:mem:devDb;MVCC=TRUE;LOCK_TIMEOUT=10000;DB_CLOSE_ON_EXIT=FALSE"
url = 'jdbc:mysql://54.169.168.27/zonalde'
driverClassName = 'com.mysql.jdbc.Driver'
username = 'root'
password = ''
dialect = org.hibernate.dialect.MySQL5InnoDBDialect
}
}

请帮忙

最佳答案

在您的DataSource.groovy中,dbCreate被注释。这意味着grails不会自动为您生成数据库模式。您可能有一个没有表的数据库。

它应该具有值create, create-drop, update, validate之一。除非您不是自己创建架构或使用某些迁移插件。

有4个值可供选择:

create - On startup of your application, this will drop and recreate your schema. This will make sure that you will always have a clean table structure, and all your data is reset on every startup. This is ideal when you are in the early stages of the project and heavily modifying your data model. You will need to spend more time on your Bootstrap though, to create all background data that you need.

create-drop - This will behave exactly like create when starting up your application, with addition that it will drop all your tables when the application is shut down properly or gracefully. I would prefer the create method, because you still have the chance to inspect your database after stopping your application.

update - This will not recreate your schema or any of your tables, but will instead try to synch the database with your current data model. This is done by adding the missing tables or columns to your database. This however is ideal when you are in the middle of development, where it is not practical to put most of your test data in the Bootstrap.

validate - this will not alter your database, but will just compare your data model with the database on start up. And create warnings if necessary. This is ideal when deploying to production environment.

关于hibernate - Grails错误spi.SqlExceptionHelper- 'field list'中的未知列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32578552/

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