ponyorm / pony

Pony Object Relational Mapper
Apache License 2.0
3.63k stars 245 forks source link

SQLite foreign key SQL incorrect while defined schema names. #654

Open QuYunpeng opened 2 years ago

QuYunpeng commented 2 years ago

With the help of ATTACH command I could seperate the table in different sqlite files. But the generation foreign key SQL is not correct for SQLite with schema defined.

` class User(db.Entity): table = ('main','user') name = orm.Required(str) car = orm.Set('Car')

class Car(db.Entity): table = ('main','car') name = orm.Required(str) owner = orm.Required(User)`

Will got below error.

line 72, in wrap_dbapi_exceptions raise OperationalError(e) pony.orm.dbapiprovider.OperationalError: near ".": syntax error

As checked it's due to below wrong foreign key referfences. Correct should "main.user" instead. CREATE TABLE "main"."car" ( "id" INTEGER PRIMARY KEY AUTOINCREMENT, "name" TEXT NOT NULL, "owner" INTEGER NOT NULL REFERENCES "main"."user" ("id") ON DELETE CASCADE )