2009-05-06 17 views
0

と私はデータベース作成スクリプトをのMySQLスキーマ生成NHibernateは

Configuration configuration = new Configuration(); 
configuration.Configure(); 
SchemaExport schemaExport = new SchemaExport(configuration); 
using(TextWriter stringWriter = new StreamWriter("create.sql")) 
{ 
    schemaExport.Execute(false, false, false, true, null, stringWriter); 
} 

とSQLを生成するには、次のコードを使用しました、それはMS SQLとよく働いた生成します。私は、MySQLに移動していたとき、私はNHibernateのに構成を変更した:

<hibernate-configuration xmlns="urn:nhibernate-configuration-2.2"> 
<session-factory> 
    <property name="connection.provider">NHibernate.Connection.DriverConnectionProvider</property> 
    <property name="connection.driver_class">NHibernate.Driver.MySqlDataDriver</property> 
    <property name="connection.connection_string">Server=localhost;Database=db;User ID=root;Password=sa;</property> 
    <property name="dialect">NHibernate.Dialect.MySQLDialect</property> 
</session-factory> 

が、SQLは、この時間を生成したエラーのためのMySQLクエリブラウザで実行does't。 ここでNHibernateはによって生成されたMySQLの作成スクリプトのサンプルです:

alter table Order drop foreign key FK_User_Order 
alter table OrderItem drop foreign key FK_Order_Item 
alter table Item drop foreign key FK742DC178AD99756A 

drop table if exists User 
drop table if exists Order 
drop table if exists OrderItem 
drop table if exists Item 
drop table if exists Category 
create table User (
    Id INTEGER NOT NULL AUTO_INCREMENT, 
    role INTEGER not null, 
    is_active TINYINT(1) not null, 
    contact_name VARCHAR(100), 
    phone VARCHAR(100), 
    address VARCHAR(100), 
    email VARCHAR(100) not null, 
    name VARCHAR(100) not null, 
    password_hash LONGBLOB not null, 
    login VARCHAR(100) not null unique, 
    is_new TINYINT(1) not null, 
    price_type INTEGER not null, 
    access_id INTEGER not null, 
    primary key (Id) 

それを

スクリプトの行を実行しようとしたとき、私は次のエラーを持っている:2あなたは あなたのSQL構文でエラーが発生しています。 が 近いラインで1

任意のアイデアを 「注文が外部キー FK_User_Order

ALTER TABLEのOrderItemは、外国のkをドロップドロップ」を使用する権利構文についてはMySQLサーバへ バージョンが対応していること取扱説明書をご確認くださいなぜNhiberanteが生成したSQLは動作しませんか?

答えて

3

schemaExport.SetDelimiter( ";");それが区切りする必要がある場合(つまり、あなたがキーワードの競合を避けるために、データベース内の受注に順序を再マッピングすることができますか?注文がキーワードである、

また別々のステートメントとしてそれらを実行するには?

+0

ユーザーもキーワードですMySqlで。あなたはテーブルの列名としてキーワードを使うことができますが、その文字列を '文字で囲む必要があります – Trygve

関連する問題