Skip to content

Commit ba3489b

Browse files
committed
add note about foreign key constraints for #42
1 parent 8c9bc13 commit ba3489b

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

lib/ecto/adapters/sqlite3.ex

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,20 @@ defmodule Ecto.Adapters.SQLite3 do
125125
126126
add :email, :string, check: %{name: "test_constraint", expr: "email != 'test@example.com')"}
127127
128+
### Handling foreign key constraints in changesets
129+
130+
Unfortunately, unlike other databases, SQLite3 does not provide the precise name of the constraint violated,
131+
but only the columns within that constraint (if it provides any information at all). Because of this, changeset
132+
functions like `Ecto.Changeset.foreign_key_constraint/3` may not work at all.
133+
134+
This is because the above functions depend on the Ecto Adapter returning the name of the violated constraint,
135+
which you annotate in your changeset so that Ecto can convert the constraint violation into the correct
136+
updated changeset when the constraint is hit during a `Ecto.Repo.update/2` or `Ecto.Repo.insert/2` operation.
137+
Since we cannot get the name of the violated constraint back from SQLite3 at `INSERT` or `UPDATE` time,
138+
there is no way to effectively use these changeset functions. This is a SQLite3 limitation.
139+
140+
See or [this GitHub issue](https://github.com/elixir-sqlite/ecto_sqlite3/issues/42) for more details.
141+
128142
### Schemaless queries
129143
130144
Using [schemaless Ecto queries][7] will not work well with SQLite. This is because

0 commit comments

Comments
 (0)