Select search mode

 

SchemaExport: include foreign keys in CREATE TABLE (for SQLite)

Obsolete

Description

Since newer versions of SQLite support foreign key enforcement, it would be nice if the schema export functionality in NHibernate could generate foreign key clauses when working with the SQLite dialect.

Right now what's stopping this from being a trivial change to the SQLiteDialect class is that NHibernate only creates foreign keys with an ALTER TABLE statement, and SQLite doesn't support that. If NHibernate supported including the foreign keys in the CREATE TABLE statement, then SQLite's foreign key support could be used.

Environment

None

Details

Assignee

Reporter

Affects versions

Priority

Who's Looking?

Open Who's Looking?

Created May 14, 2010 at 11:25 AM
Updated May 9, 2011 at 9:57 AM
Resolved May 9, 2011 at 9:57 AM

Activity

Show:

Fabio MauloMay 9, 2011 at 9:57 AM

Fixed in revision 5543 by Patrick

Bogdan CosteaOctober 20, 2010 at 4:28 PM

I've run into the same issue.
Looking at it I realized that something is fishy.

It seems that all FK's are added using ALTER's, not inlined in the CREATE TABLE, regardless of dialect.
This is really tricky, because SQLite doesn't support ALTER TABLE ADD CONSTRAINT but it supports FK's in inlined CREATE TABLE... so the problem can't really be fixed in the dialect.

A fixing patch would modify NHibernate.Mapping.Table, NHibernate.Dialect.Dialect and it would mean creating a new SQLite dialect, with a different name, just to be backward compatible.

Modifying NHibernate.Mapping.Table and NHibernate.Dialect.Dialect is required to add support for creating foreign keys in CREATE TABLE.

Would such a patch that covers Table, Dialect and a new SQLite dialect class be accepted?

Asbjørn UlsbergAugust 19, 2010 at 3:57 AM

@Matthew If you know how to create the required parts of the dialect to support foreign keys (in both create and update table statements), perhaps other people in the community (like me) can take that as a basis and somehow make it work. Would it be possible for you to create a patch that provides this functionality? It would be greatly appreciated!

Who's Looking?

Flag notifications