diff --git a/lib/ecto/migration.ex b/lib/ecto/migration.ex
index 3ee02688..58b1b355 100644
--- a/lib/ecto/migration.ex
+++ b/lib/ecto/migration.ex
@@ -834,6 +834,7 @@ defmodule Ecto.Migration do
end
def references(table, opts) when is_binary(table) and is_list(opts) do
+ opts = opts ++ Runner.repo_config(:migration_primary_key, [])
reference = struct(%Reference{table: table}, opts)
unless reference.on_delete in [:nothing, :delete_all, :nilify_all] do
diff --git a/test/ecto/migration_test.exs b/test/ecto/migration_test.exs
index 1c54d60e..c7d169c6 100644
--- a/test/ecto/migration_test.exs
+++ b/test/ecto/migration_test.exs
@@ -514,5 +514,16 @@ defmodule Ecto.MigrationTest do
assert "SELECT 2" = last_command()
end
+ test "references foreing keys types must be the same as primary defaults" do
+ %{runner: runner} = Process.get(:ecto_migration)
+ Agent.update(runner, fn state ->
+ config = Keyword.put(state.config, :migration_primary_key, [type: :binary_id])
+ Map.put(state, :config, config)
+ end)
+
+ assert references(:posts) ==
+ %Reference{table: "posts", column: :id, type: :binary_id}
+ end
+
defp last_command(), do: Process.get(:last_command)
end