I don’t get how to create a foreign key (using MariaDB) between the question table (column: chapter_ID) and chapter table (column: chapter_ID)
chapter migration:
defmodule My.Chapter do
use My.Web, :model
schema "chapter" do
field :chapter_ID, :integer
field :chapter_name, :string
timestamps()
end
end
I have this migration;
defmodule My.Repo.Migrations.CreateQuestion do
use Ecto.Migration
def change do
create table(:question, primary_key: false) do
add :question_ID, :"integer(8) unsigned", primary_key: true, autogenerate: true, null: false
add :chapter_ID, :"integer(5) unsigned", references(:chapter, column: :chapter_ID)
end
end
and a model:
defmodule My.Question do
use My.Web, :model
schema "question" do
field :question_ID, :integer
belongs_to :chapter, foreign_key: chapter_ID, My.Chapter
end
end