Question

This is my initial SQLite database

CREATE TABLE [Categories] (
  [ParentId] INT, 
  [Name] VARCHAR(100));

CREATE TABLE [Fees] (
  [CategoryId] INT, 
  [Name] VARCHAR(100), 
  [Value] VARCHAR(50), 
  [Info] VARCHAR(200));

CREATE TABLE [Markups] (
  [CategoryId] INT, 
  [UpTo] MONEY, 
  [Value] VARCHAR(50), 
  [Info] VARCHAR(200));

If I run DbMetal /provider:Sqlite /conn "Data Source=bms4.db3" /dbml:Model.dbml, it will successfully create the dbml file.

But if I add a Foreign Key, such that

CREATE TABLE [Fees] (
  [CategoryId] INT CONSTRAINT [fk_fees_categories] REFERENCES [Categories]([rowid]), 
  [Name] VARCHAR(100), 
  [Value] VARCHAR(50), 
  [Info] VARCHAR(200));

Running the same command

DbMetal /provider:Sqlite /conn "Data Source=bms4.db3" /dbml:Model.dbml

will give this error:

>>> Reading schema from SQLite database
DbMetal: The given key was not present in the dictionary.

How can I introduce a Foreign Key relationship into the DBML?

Was it helpful?

Solution

Foreign keys are checked against a unique key in the constraint. You have not declared a primary key or unique key so you need to start by doing that (It is good practice to make sure that each table has a primary key)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top