greenrobot / greenDAO

greenDAO is a light & fast ORM solution for Android that maps objects to SQLite databases.
http://greenrobot.org/greendao/
12.63k stars 2.89k forks source link

greenDAO not generating FOREIGN KEY(…) constraint in table #169

Open mbracero opened 9 years ago

mbracero commented 9 years ago

When I create a bidirectional 1:n relationship as shown below, the generator does not use any FOREIGN KEY(...) constraints on the table.

entity customer = schema.addEntity("Customer"); customer.addIdProperty(); customer.addStringProperty("name").notNull();

Entity order = schema.addEntity("Order"); order.setTableName("ORDERS"); // "ORDER" is a reserved keyword order.addIdProperty(); Property orderDate = order.addDateProperty("date").getProperty(); Property customerId = order.addLongProperty("customerId").notNull().getProperty(); order.addToOne(customer, customerId);

customer.addToMany(order, customerId); Is this normal? Is it supposed to generate FOREIGN KEY(...) constraints in the table for check value

mmartin101 commented 9 years ago

I don't think greenDAO supports Foreign Key constraints. Foreign Key support in SQLite was not added until 3.6.19. Which means it would only be supported in API 8 and up. Since greenDAO supports Android 1.6 and up I would assume that it left out Foreign Key constraints in favor of compatibility.

But I'm with you on adding support for it. :+1:

greenrobot commented 9 years ago

It could be optional if the SQLite version supports it. If not they could be ignored. API 8 sound reasonable anyway...

mykola-dev commented 8 years ago

I think we can leave in peace api8 and below. even api10. Now time to go forward

bjornwiz commented 8 years ago

We've come up with a greenDAO compatible solution which enforces foreign keys in SQLite. You can read about it on our blog (www.codepandora.com/blog) - How To Enforce Foreign Keys In greenDAO Android ORM

mcauto commented 5 years ago

We've come up with a greenDAO compatible solution which enforces foreign keys in SQLite. You can read about it on our blog (www.codepandora.com/blog) - How To Enforce Foreign Keys In greenDAO Android ORM

This link return 520 error.

mwhesse commented 4 years ago

This has been open since 2015... any plans to support it soon?