title: Composite key, `unique_constraint` issue
body: <p>I have migration like:</p>
  
  <pre><code>defmodule N.Repo.Migrations.CreateAuth do
    use Ecto.Migration
  
    def change do
      create table(:auths, primary_key: false) do
        add :oauth_id, :string, primary_key: true
        add :provider, :string, primary_key: true
  
        add :user_id, references(:users, on_delete: :nothing, type: :binary_id)
  
        timestamps()
      end
  
      create index(:auths, [:user_id])
    end
  end
  </code></pre>
  
  <p>And model configured as follows:</p>
  
  <pre><code>defmodule N.Auth do
    use N.Web, :model
  
    @primary_key false
    schema "auths" do
      field :oauth_id, :string, primary_key: true
      field :provider, :string, primary_key: true
  
      belongs_to :user, N.User
  
      timestamps()
    end
  
    @doc """
    Builds a changeset based on the `struct` and `params`.
    """
    def changeset(struct, params \\ %{}) do
      struct
      |&gt; cast(params, [:oauth_id, :provider])
      |&gt; validate_required([:oauth_id, :provider])
      |&gt; unique_constraint(:oauth_id, :auths_oauth_id_index)
    end
  end
  </code></pre>
  
  <p>Following the suggestion from <a href="http://www.phoenixframework.org/docs/ecto-custom-primary-keys#section-composite-primary-keys" rel="nofollow">Phoenix guidelines</a>.</p>
  
  <p>In my tests:</p>
  
  <pre><code>defmodule N.AuthTest do
    use N.ModelCase
  
    import N.Factory
  
    alias N.Auth
  
    test "changeset with duplicates" do
      auth_params =
        %{provider: :facebook,
          oauth_id: "1234"}
      insert(:auth, auth_params)
  
      changeset = Auth.changeset(%Auth{}, auth_params)
  
      assert {:error, changeset} = Repo.insert(changeset)
    end
  end
  </code></pre>
  
  <p>Unfortunately, when running them, I have following error:</p>
  
  <pre><code>  1) test N.Auth.changeset/2 changeset with duplicates (N.AuthTest)
       test/models/auth_test.exs:31
       ** (FunctionClauseError) no function clause matching in Access.fetch/2
       stacktrace:
         (elixir) lib/access.ex:147: Access.fetch(:auths_oauth_id_index, :name)
         (elixir) lib/access.ex:179: Access.get/3
         (ecto) lib/ecto/changeset.ex:1629: Ecto.Changeset.unique_constraint/3
         test/models/auth_test.exs:37: (test)
  </code></pre>
  
  <p>If I understand it correctly, this is due to lack of:</p>
  
  <pre><code>create unique_index(:auths, [:oauth_id, :provider])
  </code></pre>
  
  <p>like described in <a href="https://hexdocs.pm/ecto/Ecto.Changeset.html#unique_constraint/3" rel="nofollow"><code>unique_constraint/3</code></a> documentation. Obviously, I don't want to create the index, as it's created automatically by setting the composite primary key.</p>
  
  <p>Do you have any advice how to take that further?</p>
  
  <p><strong>UPDATE</strong></p>
  
  <p>The index name used here is suggested by <code>Ecto</code> itself - when I use code without specifying the index name, like so:</p>
  
  <pre><code>    |&gt; unique_constraint(:oauth_id)
  </code></pre>
  
  <p>when I run the test, the error messages is as follows:</p>
  
  <pre><code>  1) test N.Auth.changeset/2 changeset with duplicates (N.AuthTest)
       test/models/auth_test.exs:31
       ** (Ecto.ConstraintError) constraint error when attempting to insert struct:
  
           * unique: auths_pkey
  
       If you would like to convert this constraint into an error, please
       call unique_constraint/3 in your changeset and define the proper
       constraint name. The changeset defined the following constraints:
  
           * unique: auths_oauth_id_index
  
       stacktrace:
         (ecto) lib/ecto/repo/schema.ex:403: anonymous fn/4 in Ecto.Repo.Schema.constraints_to_errors/3
         (elixir) lib/enum.ex:1183: Enum."-map/2-lists^map/1-0-"/2
         (ecto) lib/ecto/repo/schema.ex:393: Ecto.Repo.Schema.constraints_to_errors/3
         (ecto) lib/ecto/repo/schema.ex:193: anonymous fn/11 in Ecto.Repo.Schema.do_insert/4
         (ecto) lib/ecto/repo/schema.ex:595: anonymous fn/3 in Ecto.Repo.Schema.wrap_in_transaction/6
         (ecto) lib/ecto/adapters/sql.ex:472: anonymous fn/3 in Ecto.Adapters.SQL.do_transaction/3
         (db_connection) lib/db_connection.ex:973: DBConnection.transaction_run/4
         (db_connection) lib/db_connection.ex:897: DBConnection.run_begin/3
         (db_connection) lib/db_connection.ex:671: DBConnection.transaction/3
         test/models/auth_test.exs:41: (test)
  </code></pre>
  
  <p>The same error occurs, when I'm trying <a href="https://hexdocs.pm/ecto/Ecto.Changeset.html#check_constraint/3" rel="nofollow"><code>check_constraint/3</code></a>, like:</p>
  
  <pre><code>    |&gt; check_constraint(:oauth_id, name: :auths_oauth_id_index)
  </code></pre>