greenDAO icon indicating copy to clipboard operation
greenDAO copied to clipboard

greenDAO not generating FOREIGN KEY(…) constraint in table

Open mbracero opened this issue 10 years ago • 6 comments

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

mbracero avatar Feb 03 '15 14:02 mbracero

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:

mmartin101 avatar Apr 09 '15 18:04 mmartin101

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

greenrobot avatar Jun 30 '15 19:06 greenrobot

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

mykola-dev avatar Oct 18 '15 14:10 mykola-dev

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

bjornwiz avatar Feb 02 '16 09:02 bjornwiz

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.

mcauto avatar Jan 11 '19 07:01 mcauto

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

mwhesse avatar May 07 '20 04:05 mwhesse