title: Elixir/Phoenix, running into error when adding a row to my 'topics' table in Postgres using Repo.insert(changeset)
body: <p>I've got a &quot;Topics&quot; context, which defines a single &quot;topics&quot; table in my db, and it only has one field &quot;title&quot;, like so:</p>
  <p>topic.ex</p>
  <pre><code>defmodule Discuss.Topic do
    use Ecto.Schema
    import Ecto.Changeset
  
    schema &quot;topics&quot; do
      field :title, :string
      timestamps()
    end
  
    def changeset(topic, attrs) do 
      topic
      |&gt; cast(attrs, [:title]) 
      |&gt; validate_required([:title]) 
    end
  end
  </code></pre>
  <p>I run a command in the terminal to create my migration with &quot;mix ecto.gen.migration add_topics&quot;, to add a table 'topics' in my db which contains only one 'title' column:</p>
  <p>20220728225556_add_topics.exs</p>
  <pre><code>defmodule Discuss.Repo.Migrations.AddTopics do
    use Ecto.Migration
  
    def change do
      create table(:topics) do
        add :title, :string
      end
    end
  end
  </code></pre>
  <p>to which I then run &quot;mix ecto.migrate&quot; to execute the migration and make the table in Postgres, which was successful. I now have only one table in my db called 'topics', and it only contains two columns, the id (which is by default), and 'title', which holds string values.</p>
  <p>The user can now submit a form containing just one field to add a 'topic' to my topics table, this is done by running a POST request to '/topics' when the form gets submitted.</p>
  <p>When my router gets a POST request to '/topics', it runs this &quot;create&quot; function in my topic_controller.ex file, which obtains that 'title' property from the form and applies it to our changeset before we use it to add a new row to my 'topics' table with &quot;Repo.insert(changeset)&quot;.</p>
  <p>topic_controller.ex:</p>
  <pre><code>defmodule DiscussWeb.TopicController do
  
    use DiscussWeb, :controller 
    
    alias Discuss.Topic
    alias Discuss.Repo
  
    def new(conn, _params) do
      # the 'conn' struct holds data for the request and the response.
      struct = %Topic{} # this struct starts off empty because we don't have data for the form yet.
      params = %{} 
      changeset = Topic.changeset(struct, params)
      render conn, &quot;new.html&quot;, changeset: changeset
    end
  
  
    def create(conn, params) do 
      %{&quot;topic&quot; =&gt; topic} = params 
  # we pattern match a 'topic' variable to get the 'title' property from the form, which I can then view using 'IO.inspect topic'. 
      
      changeset = Topic.changeset(%Topic{}, topic) 
  # here, I'm adding my 'title' property to my empty pre-existing changeset, which is successful when I inspect it afterwards.  
  
      Repo.insert(changeset) 
  #this is the function that should be adding a new row to my 'topics' table with the 'title' property we obtained from the form, but instead throws the error I'm experiencing. 
      
    end
  end
  </code></pre>
  <p>I'm aware that I'd be given an error for not redirecting my page anywhere anyway, but I should at least still be seeing a new row added to my 'topics' table when the form gets submitted. Instead, I'm given the error you see below saying &quot;ERROR 42703 (undefined_column) column &quot;inserted_at&quot; of relation &quot;topics&quot; does not exist&quot;, and even after regenerating my migration and running it a second time, I can't seem to narrow down why my build is telling me that I'm adding a row to a 'topics' table that doesn't exist, when it matter-of-factly, exists. <a href="https://i.stack.imgur.com/cAtcZ.jpg" rel="nofollow noreferrer">Error seen when adding a row to the 'topics' table. </a></p>
  <p><a href="https://i.stack.imgur.com/FoD0D.jpg" rel="nofollow noreferrer">Proof my 'topics' table exists in my Postgres db</a></p>