Generating MySql Schema with NHibernate

I used the following code to create a database script

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

      

and sql, it works great with MS SQL. When I had to switch to MySql, I changed my NHibernate config to:

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

      

but the sql generated this time fails in MySQL Query Browser due to errors. Here's a sample of creating a mysql script, generated by Nhibernate:

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) 

      

I got the following error when trying to execute it

Script line: 2 You have an error in your SQL syntax; check the manual that matches your MySQL server version for the correct syntax to use next to the foreign order key FK_User_Order

change table OrderItem drop foreign k 'on line 1

Any ideas why the SQL generated in Nhiberante won't work?

0


a source to share


1 answer


schemaExport.SetDelimiter (";"); if it needs to be delimited (i.e. run them as separate statements



Also, is the keyword ordering? can you reassign the order to Orders in the database to avoid keyword conflict?

+3


a source







All Articles