question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

sync tries to always create a table

See original GitHub issue

Hi there.

following the examples to work on a small side-project I have.

if I use

export class SessionModel extends Model {
  static table = "sessions";
  static timestamps = true;
  static fields = {
    id: {
      primaryKey: true,
      autoIncrement: true,
    },
    startTimestamp: DATA_TYPES.INTEGER,
    endTimestamp: DATA_TYPES.INTEGER,
    createdAt: DATA_TYPES.INTEGER,
    price: DATA_TYPES.STRING,
    category: DATA_TYPES.STRING,
    subCategory: DATA_TYPES.STRING,
    state: DATA_TYPES.STRING,
    withUser: DATA_TYPES.STRING,
    notes: DATA_TYPES.STRING,
  };
}

db.link([SessionModel]);

await db.sync({ drop: false /* true */ });

, the first time it runs, it creates the tables and everything is fine. Every time after that, it fails trying to create a table

( logs from my 2 containers, one with the postgres db, and one with the deno api )

bp-db_1   | 2020-05-24 19:40:10.668 UTC [306] ERROR:  relation "sessions" already exists
bp-db_1   | 2020-05-24 19:40:10.668 UTC [306] STATEMENT:  create table "sessions" ("id" serial primary key, "startTimestamp" integer, "endTimestamp" integer, "createdAt" integer, "price" varchar(255), "category" varchar(255), "subCategory" varchar(255), "state" varchar(255), "withUser" varchar(255), "notes" varchar(255), "created_at" timestamptz not null default CURRENT_TIMESTAMP, "updated_at" timestamptz not null default CURRENT_TIMESTAMP)
bp-api_1  | error: Uncaught PostgresError: relation "sessions" already exists
bp-api_1  |   return new PostgresError(errorFields);
bp-api_1  |          ^
bp-api_1  |     at parseError (https://deno.land/x/postgres/error.ts:105:10)
bp-api_1  |     at Connection._processError (https://deno.land/x/postgres/connection.ts:430:19)
bp-api_1  |     at Connection._simpleQuery (https://deno.land/x/postgres/connection.ts:297:20)
bp-api_1  |     at async Connection.query (https://deno.land/x/postgres/connection.ts:539:16)
bp-api_1  |     at async Client.query (https://deno.land/x/postgres/client.ts:24:12)
bp-api_1  |     at async PostgresConnector.query (https://deno.land/x/denodb/lib/connectors/postgres-connector.ts:45:21)
bp-api_1  |     at async Function._createInDatabase (https://deno.land/x/denodb/lib/model.ts:75:5)
bp-api_1  |     at async Promise.all (index 0)
bp-api_1  |     at async file:///app/db.ts:32:1

If I switch drop to true, it will wipe out everything (after the first time)

I’m sure I’m missing something. How can I make it create the table only when it doesn’t exist??

Thank you.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:2
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

3reactions
eveningkidcommented, May 24, 2020

Hey Antonis,

You are right, it actually tries to create the tables every single time. I will work on this right now and update this issue.

2reactions
AntouanKcommented, May 28, 2020

yeah, my bad, I forgot the “drop: true”. I removed that and it’s fine.

thanks 👍

Read more comments on GitHub >

github_iconTop Results From Across the Web

Sequelize sync and Node.js not create table - Stack Overflow
In my case i just import Model to app.js const sequelize = require("./src/Utils/database"); const User = require(".
Read more >
Data Factory auto create table in Copy activity doesn't seem to ...
I'm trying to create copy activities where the source table is replicated into the Sink database, and the table is created according to...
Read more >
How to Use Airtable Sync - YouTube
This new tool gives us the ability to connect data across our Airtable bases (databases)! If you find yourself creating the same tables...
Read more >
Airtable Sync - Basic Setup
The Airtable Sync feature allows you to sync records from a source base to one or more destination bases to create a single...
Read more >
How to avoid Table Synchroniser... - Microsoft Dynamics AX ...
In your table, you have data with duplicate value in primary key/Unique index field. when you run Check/synchronization it will show the table...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found