title: PostgreSQL - SequelizeDatabaseError with join table (Code: 42P01)
body: <p>I am trying to create a join table for many to many relationships. </p>
  
  <p>I am getting the following error:</p>
  
  <pre><code>"name": "SequelizeDatabaseError",
  "parent": {
      "name": "error",
      "length": 110,
      "severity": "ERROR",
      "code": "42P01",
      "position": "13",
      "file": "parse_relation.c",
      "line": "1160",
      "routine": "parserOpenTable",
      "sql": "INSERT INTO \"user_routes\" (\"id\",\"userId\",\"routeId\",\"createdAt\",\"updatedAt\") VALUES (DEFAULT,'1','1','2017-11-15 03:57:21.791 +00:00','2017-11-15 03:57:21.791 +00:00') RETURNING *;"
  },
  </code></pre>
  
  <p>The relationship is between <code>User</code> and <code>Route</code>:</p>
  
  <pre><code>module.exports = (sequelize, DataTypes) =&gt; {
    const Route = sequelize.define("Route", {
      open: {
        type: DataTypes.BOOLEAN,
        allowNull: true
      }
    });
  
    Route.associate = models =&gt; {
      Route.belongsToMany(models.User, {
        through: "userRoutes",
        as: "users"
      });
    };
    return Route;
  };
  
  
  module.exports = (sequelize, DataTypes) =&gt; {
    var User = sequelize.define("User", {
      email: DataTypes.TEXT,
      password: DataTypes.TEXT
    });
  
    User.associate = models =&gt; {
      User.belongsToMany(models.Route, {
        through: "userRoutes",
        as: "routes"
      });
    };
  
    return User;
  };
  </code></pre>
  
  <p>Migration files for user and route does not have much but just the basics. For join table:</p>
  
  <pre><code>"use strict";
  module.exports = {
    up: (queryInterface, Sequelize) =&gt; {
      return queryInterface.createTable("user_route", {
        id: {
          allowNull: false,
          autoIncrement: true,
          primaryKey: true,
          type: Sequelize.INTEGER
        },
        createdAt: {
          allowNull: false,
          type: Sequelize.DATE
        },
        updatedAt: {
          allowNull: false,
          type: Sequelize.DATE
        },
        userId: {
          type: Sequelize.INTEGER,
          onDelete: "CASCADE",
          references: {
            model: "Users",
            key: "id"
          }
        },
        routeId: {
          type: Sequelize.INTEGER,
          onDelete: "CASCADE",
          references: {
            model: "Routes",
            key: "id"
          }
        }
      });
    },
    down: (queryInterface, Sequelize) =&gt; {
      return queryInterface.dropTable("user_route");
    }
  };
  </code></pre>
  
  <p>My controller and route is as following:</p>
  
  <pre><code>  create(req, res) {
      return UserRoutes.create({
        userId: req.body.userId,
        routeId: req.body.routeId
      })
        .then(userRoute =&gt; res.status(201).send(userRoute))
        .catch(err =&gt; res.status(400).send(err));
    },
  
  
  
  app.post("/api/userRoutes", userRoutesController.create);
  </code></pre>
  
  <p>So when I try to post to that route, I get the error message on the top of the post.</p>