Invalid association in Ecto schema

Hi guys, I do have a problem regarding ecto queries. As you can see below, you’ll find that I’m trying to link users table to projects table. But unfortunately, it doesn’t work as error is trying to find “users_id” column on projects table on which is named “employer_id”. How can I link it using the specified column name which is employer_id belongs_to(:employer, User)?

I’m trying to call this code:

    projects =
      Ecto.assoc(user, :projects)
      |> Repo.all()


warning: invalid association `projects` in schema Ecosystem.User: associated schema Ecosystem.Project does not have field `user_id`
  lib/ecosystem/user.ex:1: Ecosystem.User (module)

User Schema:

  schema "users" do
    field(:email, :string)
    field(:hash_password, :string)
    field(:password, :string, virtual: true)

    has_many(:projects, Project)


Projects Schema:

  schema "projects" do
    field(:code, :string)
    field(:name, :string)
    field(:start_date, :utc_datetime)
    field(:end_date, :utc_datetime)
    field(:remarks, :string)
    field(:status, Status, default: :pending)

    belongs_to(:employer, User)


2 posts were merged into an existing topic: Invalid ecto association missing field