0

i am creating table on heroku successfully but the problems is foreign key when add foreign key it will automatically created in small letter by default postgres accept foreign key like serviceId format

this is my table

CREATE TABLE service_categories (
    id serial PRIMARY KEY,
    "serviceId"                 integer   NOT NULL,
    service_category_name       VARCHAR ( 50 )  NOT NULL,
    "createdAt"                 TIMESTAMP DEFAULT NOW(),
    "updatedAt"                 TIMESTAMP DEFAULT NOW()
);

but on heroku its created serviceid rather then serviceId any body can help how can i create foreign key like serviceId

Shahid
  • 159
  • 5
  • 14
  • The tag `sql` says: "...and a tag for the DBMS implementation (e.g. MySQL, PostgreSQL, Oracle, MS SQL Server, IBM DB2, etc.) being used." **Please correct the tags** Or do you work with `mysql` AND `postgresql` ????? – Luuk May 28 '22 at 18:04
  • Please share the code that you are using (or trying) to create this foreign key, and the table definition of the table you are creating a foreign key to. – Luuk May 28 '22 at 18:05
  • Using quoted identifiers is strongly discouraged. Bit if you create the table with the code in your question (using the dreaded double quotes) then the case **will** be preserved and the column will be named `"serviceId"`. If it isn't, then I guess something in your toolset removes the double quotes –  May 28 '22 at 18:16
  • i am using `"serviceId"` like this but i do not know why its not creating as per expectation – Shahid May 28 '22 at 18:57
  • As I said: if run like that, Postgres **will** create a mixed case column name. [See here](https://dbfiddle.uk/?rdbms=postgres_14&fiddle=69ef080eaca9320dab77aeec57a35d5f) - if it doesn't there is something in your tool chain that prevents this. –  May 28 '22 at 19:02

1 Answers1

0

just double quotes in the model like

const Order = db.define("my_orders", {
    id: {
        type: Sequelize.INTEGER,
        autoIncrement: true,
        allowNull: false,
        primaryKey: true,
    },
    "serviceSubCategoryId": {
        type: Sequelize.INTEGER
    },
   "userId": {
        type: Sequelize.INTEGER
    }
   
});
Shahid
  • 159
  • 5
  • 14