Ask questionsRelation does not exist (Foregin Key)

<!-- Before submitting an issue, please consult our docs ( and check whether your problem was already reported ( -->

<!-- Please make sure you are posting an issue pertaining to sequelize-typescript. If you are having an issue with sequelize itself, please consult the sequelize team ( -->

Versions <!-- Please let us know which sequelize, sequelize-typescript and typescript version are you using -->

  • sequelize: 5.10.2
  • sequelize-typescript: 1.0.0-beta.3
  • typescript 3.5.3

I'm submitting a ... <!-- (check one with "x") --> [x] bug report [ ] feature request

Actual behavior: <!-- Describe how the bug manifests. --> First time using sequelize and sequelize-typescriot. I have two models, device and measurement. A device can hav many measurements. A measurement is from exactly one device.

The Table "Devices" is created. The Table measurement can't be created. The error is that the relation "Devices" does not exist.

Executing (default): CREATE TABLE IF NOT EXISTS "test"."Measurements" ("id"   SERIAL , "deviceType" VARCHAR(255), "deviceId" INTEGER REFERENCES "Devices" ("id") ON DELETE CASCADE ON UPDATE CASCADE, "createdAt" TIMESTAMP WITH TIME ZONE NOT NULL, "updatedAt" TIMESTAMP WITH TIME ZONE NOT NULL, PRIMARY KEY ("id"));
(node:14524) UnhandledPromiseRejectionWarning: SequelizeDatabaseError: Relation »Devices« does not exist

It looks like the schema "test" is missing in the SQL. After INTEGER REFERENCES it should be "test"."Devices" shouldn't it?

Expected behavior: Create the table :)

Steps to reproduce: <!-- Please explain the steps required to duplicate the issue, especially if you are able to provide a sample application. -->

Related code:

export class Device extends Model<Device> 
    euid: string;

    type: String;

    @HasMany(() => Measurement)
    measurements: Measurement[];

export class Measurement extends Model<Measurement> 

    deviceType: string;

    @ForeignKey(() => Device)
    deviceId: number;


async function preparePostgres()
    const sequelize =  new Sequelize({
        database: 'xxx',
        host: "localhost",
        port: 5432,
        dialect: 'postgres',
        username: 'xxx',
        password: 'xxx'

    sequelize.addModels([Device, Measurement]);

    let schemas : any[] = await sequelize.showAllSchemas({});
    if (!schemas.includes("test"))
        await sequelize.createSchema("test", {});
    await sequelize.sync({schema: 'test'});

    return sequelize;

preparePostgres().then((sequelize) => {
    let test ={euid: "haha", type: "asdf"});;

Answer questions RobinBuschmann

Closing this due to inactivity

Github User Rank List