title: Setting up Phoenix Framework and Ecto to use UUIDs: how to insert the generated value?
body: <p>A few days ago I started using Elixir and the Phoenix Framework (v 0.12.0) with a Postgres database. I'm trying to create a table which has a UUID primary key, which I prefer over the sequential default. </p>
  
  <p>After using <code>mix phoenix.gen.html</code> to generate the model and migration files and following the other steps in the Phoenix docs, I have changed </p>
  
  <pre><code>def model do
      quote do
        use Ecto.Model
      end
    end
  </code></pre>
  
  <p>in <code>web.ex</code> to</p>
  
  <pre><code>def model do
    quote do
      use Ecto.Model
      @primary_key {:id, :uuid, []}
      @foreign_key_type :uuid
    end
  end
  </code></pre>
  
  <p>as is mentioned in the Ecto docs. I have also changed the migration to</p>
  
  <pre><code>create table(:tblname, primary_key: false) do
    add :id, :uuid, primary_key: true
    [other columns]
  end
  </code></pre>
  
  <p>Unfortunately, when I try to add an entry to the table from the auto-generated form, I get an error because the <code>id</code> is null. If I manually add an <code>id</code>-column to the model, I receive an error that the column already exists. If I neglect to set <code>primary_key</code> to false in <code>table/2</code> and remove the <code>id</code> column, the table is generated with a sequential <code>id</code>-column.</p>
  
  <p>Do I need to manually set the <code>id</code> in the changeset, or have I made an error in setting up my app to use UUIDs? Thanks in advance</p>