Friday 28 April 2017

Heroku postgres unique constraint error

I have a local sqlite db that was created using the knex library. It runs perfectly fine on my local machine.

I deployed the same knex syntax on heroku but under postgres however I get the error:

error: alter table "dAppTable" add constraint 
"dapptable_dappname_unique" unique ("dAppName") - column "dAppName" 
named in key does not exist

This is unusual as the table is clearly stated below:

exports.up = function(knex, Promise)
{
  console.log('create dApp table');

  return knex.schema.createTableIfNotExists('dAppTable', function(table)
  {
    table.increments('id');
    table.string('dAppName').unique();
    table.string('abi');
    table.string('contractAddress').unique();
  })
};

exports.down = function(knex, Promise)
{
    return knex.schema.dropTableIfExists('dAppTable').then(function ()
    {
        console.log('dAppTable table was dropped');
    })
};

Here is the connection config file, production is used:

production: {
    client: 'postgresql',
    connection: process.env.DATABASE_URL,
    pool: {
        min: 2,
        max: 10
    },
    migrations: {
        tableName: 'dAppTable',
        directory: __dirname + '/migrations'
    },
    seeds: {
        directory: __dirname + '/seeds'
    }
}



via James

No comments:

Post a Comment