Skip to content

Commit ae9eaa9

Browse files
committed
Treat the case if there is no 'ForeignKeyIndexConvention' registered.
1 parent 3183fac commit ae9eaa9

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

SQLite.CodeFirst/SqliteInitializerBase.cs

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,19 @@ protected SqliteInitializerBase(DbModelBuilder modelBuilder)
3434
// See https://github.com/msallin/SQLiteCodeFirst/issues/7 for details.
3535
modelBuilder.Conventions.Remove<TimestampAttributeConvention>();
3636

37-
// Place the own ForeinKeyIndexConvention right after the original.
38-
// The own convention will rename the automatically created indicies by using the correct scheme.
39-
modelBuilder.Conventions.AddAfter<ForeignKeyIndexConvention>(new SqliteForeignKeyIndexConvention());
37+
// By default there is a 'ForeignKeyIndexConvention' but it can be removed.
38+
// And there is no "Contains" and no way to enumerate the ConventionsCollection.
39+
// So a try/catch will do the job.
40+
try
41+
{
42+
// Place the own ForeinKeyIndexConvention right after the original.
43+
// The own convention will rename the automatically created indicies by using the correct scheme.
44+
modelBuilder.Conventions.AddAfter<ForeignKeyIndexConvention>(new SqliteForeignKeyIndexConvention());
45+
}
46+
catch (InvalidOperationException exception)
47+
{
48+
// Ignore it.
49+
}
4050
}
4151

4252
/// <summary>

0 commit comments

Comments
 (0)