Naming collision with foreign keys

While running the docker-compose command to start the backend for my local postgresql database I get the following error:

Error: Naming collision between attribute ‘my-field-id’ and association ‘my-field-id’ on model mytable. To remedy this, change either foreignKey or as in your association definition at Object.checkNamingCollision (/usr/src/app/node_modules/sequelize/lib/associations/helpers.js:5:11)

I have a postgresql database with about 30 tables and a bunch of foreign keys throughout the tables. Most of the foreign keys have the same field name in both tables. This works fine in postgresql and all the tools we’ve used with it. Changing the names of the fields would be non-trivial because of the amount of api nodejs code that uses these fields. Is there a simple fix for this naming collision error or am I misunderstanding this error?

:warning:This is a template you must use to report issues. :warning:
You can also drag images, videos and include Preformatted text.

Feature(s) impacted

Please describe in this mandatory section the feature(s) that will be discussed in this topic.
Cannot run start the backend via docker-compose because of a naming collision error when the database field has the same name as the field that a foreign key points to.

Observed behavior

Please describe in this mandatory section the current behavior you observe.
Starting the backend fails with a naming collision when the database field has the same name as the field that a foreign key points to.

Expected behavior

Please describe in this mandatory section the behavior you are expecting.
I would expect the system would not care if the database field has the same name as the field that a foreign key points to.

Failure Logs

In this optional section, please:

  • include any relevant log snippets if necessary,
  • or remove this section if left empty.
    Error: Naming collision between attribute ‘my-field-id’ and association ‘my-field-id’ on model mytable2. To remedy this, change either foreignKey or as in your association definition at Object.checkNamingCollision (/usr/src/app/node_modules/sequelize/lib/associations/helpers.js:5:11)

Context

Please provide in this mandatory section, the relevant information about your configuration:

  • Project name: my-project-name
  • Team name: none
  • Environment name: win10 with docker desktop
  • Agent type & version: ?
  • Recent changes made on your end if any: none

Hey @sirscalawag :wave:

Did you try the suggested fix? If you are using a forest-cli generated project, the as option should only have an impact inside the generated project.

To remedy this, change either foreignKey or as in your association definition at Object.checkNamingCollision

(See javascript - Sequelize: Naming collision between attribute 'playlist' and association 'playlist'? - Stack Overflow)

Let me know if that helps :pray: