eveningkid / denodb

MySQL, SQLite, MariaDB, PostgreSQL and MongoDB ORM for Deno

Home Page:https://eveningkid.com/denodb-docs

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Error creating non-integer ID table

fabrv opened this issue · comments

Adding more than one non-integer ID table with PostgreSQL throws the following error: PostgresError: relation "id" already exists

Below is an example of the code that produces the error:

import { Database, DataTypes, Model } from 'https://deno.land/x/denodb/mod.ts';

const db = new Database(...);

class Test1 extends Model {
  static table = 'test1';
  static timestamps = true;

  static fields = {
    id: {
      type: DataTypes.STRING,
      primaryKey: true,
    }
  };
}

class Test2 extends Model {
  static table = 'test2';
  static timestamps = true;

  static fields = {
    id: {
      type: DataTypes.STRING,
      primaryKey: true,
    }
  };
}

db.link([Test1, Test2]);
await db.sync({drop: true});

The problem can be workaround by either renaming the id column or by changing the type to INTEGER. However having more than one string primary key named id should be possible, specially because the example in the docs is like that.(https://eveningkid.com/denodb-docs/docs/guides/foreign-key).

This issue is probably related to #101 and #258