text: Q:
  
  Association cause foreing key mismatch error
  
  I am currently experimenting on sequelize.js and more specifically in associations. What i am trying to achieve is the following. I have to models:
  
  user
  position
  
  My logic is the following:
  
  A user can or cannot have a position assigned to it
  If a user has a position, the id of the position is stored in field "assignedPositionId" of users table.
  If a user does not have a position, then "assignedPositionId" value is set to null.
  A position can be assigned to more than one users
  
  The issue i am facing is, that i can successfully create a user, but i am unable to create a position! I always keep getting the error message:
  SQLITE_ERROR: foreign key mismatch - "positions" referencing "users"
  
  User.hasOne(Position, {
    sourceKey: "assignedPositionId",
    foreignKey: "id",
    as: "position"
  });
  
  Position.hasMany(User, {
    sourceKey: "id",
    foreignKey: "assignedPositionId",
    as: "users",
  
  });
  
  I know it's something more than easy - maybe it's late but i really can't figure out what goes wrong! Your help is highly appreciated!
  
  A:
  
  @KenOn10, thank you for your providing a suggestion. After carefully reading documentation and performing several tests, i ended up with the following approach, which works perfectly:
  User.hasMany(Position, {
    as: "position",
    sourceKey: "assignedPositionId",
    foreignKey: "id",
    constraints: false
  });
  
  Position.belongsTo(User, {
    as: "users",
    foreignKey: "assignedPositionId",
    constraints: false
  });
  
  Thank you again for your time.
  
  