2015-09-15 47 views
0

我已經Foriegn 2個Grails領域類之間的主要關係艦未知列(表)Grails的錯誤spi.SqlExceptionHelper - 在「字段列表」

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 
     } 
    } 

請幫

+0

貴表「字段列表」沒有列「service_provider_id」?畢竟這是錯誤信息。 – cfrick

+0

沒有名稱字段列表的表格。這是一般性錯誤。 –

+0

,但錯誤會指示列丟失。也許你可以添加更多關於使用過的數據庫的信息(例如,它是inmem h2的缺省值還是你試圖映射現有的數據庫)。 – cfrick

回答

0

在您的DataSource.groovy的dbCreate被註釋掉。這意味着grails不會爲你自動生成db模式。你可能有一個沒有表的數據庫。

它應該有一個值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. 
相關問題