eveningkid / denodb

MySQL, SQLite, MariaDB, PostgreSQL and MongoDB ORM for Deno
https://eveningkid.com/denodb-docs
MIT License
1.93k stars 129 forks source link

Error creating non-integer ID table #333

Open fabrv opened 2 years ago

fabrv commented 2 years ago

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