Dismiss
Announcing Stack Overflow Documentation

We started with Q&A. Technical documentation is next, and we need your help.

Whether you're a beginner or an experienced developer, you can contribute.

Sign up and start helping → Learn more about Documentation →

I created a node express application with postgresql and node.js. I decided to put it on heroku. I created my postgresql database by using the add-on of heroku. I can see my database (username/password/uri etc.)

I can ping the heroku app but when I try to create a user I get a 400 error. I checked the logs and the problem is I can not create the tables.

Here is my app.js which should create the models using ORM.

var db = require('sequelize-connect');
// Database sequelize
var connectionString;
var username;
var password;
var database;
if (process.env.NODE_ENV === 'development'){
    connectionString = global.localConnectionString;
    database = global.nameDatabase_development;
    username = global.usernameDatabase_development;
    password = global.passwordDatabase_development;
}else{
    connectionString = global.productionConnectionString;
    database = global.nameDatabase_production;
    username = global.usernameDatabase_production;
    password = global.passwordDatabase_production;
}

var sequelize = new Sequelize(connectionString);

// Model ORM configurations
var discover = path.join(__dirname, 'models');
var matcher = function (file) {
    return true;
}
var orm = new db(
    database,
    username,
    password,
    {
        dialect: 'postgres',
        port: 5432,
        force: true
    },
    discover,
    matcher
);

I got the database name/username/password from my heroku page. Do I have to create the tables manually on heroku? I thought sequelize-connect was used for that? How do I create tables on heroku?

share|improve this question

I think you should handle DB migration by yourself because it has nothing to do with what ORM you are using. ORM is just a tool for you to manipulate sql data more easily and make your code readable.

Usually, an ORM will provide some scripts for you to migrate DB. In sequelize, you can check out its cli repo which I use it a lot.

also, you need to add migration script during the process of deploy to heroku You can check out here

Thus, the step would be

  1. deploy your app to heroku
  2. heroku starts to install your npm dependency
  3. heroku starts to run migration scripts e.g. db:migrate in sequelize-cli (THIS IS WHAT YOU MISS)
  4. after migration, reload your heroku app
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.