Error Creating Foreign Key On Item_id Check Data Types
Contents |
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta
Error Creating Foreign Key On Name (check Data Types)
Discuss the workings and policies of this site About Us Learn error creating foreign key on table (check data types) more about Stack Overflow the company Business Learn more about hiring developers or posting ads with us Stack
#1452 - Cannot Add Or Update A Child Row: A Foreign Key Constraint Fails
Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 4.7 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up MySQL Error creating foreign key on
MySQL Error creating foreign key on gender (check data types) The SitePoint Forums have moved. You can now find them here. This forum is now closed to new posts, but you can browse existing content. You can find out more information about the move and how to open a new account (if necessary) here. If you get stuck you can get support by emailing forums@sitepoint.com If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum http://stackoverflow.com/questions/21711232/mysql-error-creating-foreign-key-on-columname-check-data-types that you want to visit from the selection below. SitePoint Sponsor User Tag List Results 1 to 5 of 5 Thread: Error creating foreign key on gender (check data types) Thread Tools Show Printable Version Subscribe to this Thread… Display Linear Mode Switch to Hybrid Mode Switch to Threaded Mode Jun 20, 2009,12:45 #1 qazwsxedc View Profile View Forum Posts SitePoint Member Join Date Jan 2008 Posts 16 Mentioned 0 Post(s) http://www.sitepoint.com/forums/showthread.php?622949-Error-creating-foreign-key-on-gender-(check-data-types) Tagged 0 Thread(s) Error creating foreign key on gender (check data types) Hi there, wonder if anyone has had this problem? I'm getting this error message - Error creating foreign key on gender (check data types) even though the data types of the fields I'm trying to create a constraint between are identical - int(2) unsigned. Hope someone can stop me tearing out what little hair I have left... Jun 20, 2009,13:14 #2 qazwsxedc View Profile View Forum Posts SitePoint Member Join Date Jan 2008 Posts 16 Mentioned 0 Post(s) Tagged 0 Thread(s) Never mind, recreated the tables from scratch and it's working now for some reason. Jun 20, 2009,15:37 #3 r937 View Profile View Forum Posts SQL Consultant Join Date Jul 2002 Location Toronto, Canada Posts 39,347 Mentioned 63 Post(s) Tagged 3 Thread(s) how many different values of gender are you expecting? INTEGER UNSIGNED gives you just over 4 billion, i hope that's enough ... rudy.ca | @rudydotca Buy my SitePoint book: Simply SQL "giving out my real stuffs" Jun 21, 2009,05:55 #4 qazwsxedc View Profile View Forum Posts SitePoint Member Join Date Jan 2008 Posts 16 Mentioned 0 Post(s) Tagged 0 Thread(s) Ha, yeah it just might be... would it cause any problems though? I thought that with it being int(2
Sign in Pricing Blog Support Search GitHub This repository Watch 268 Star 7,700 Fork 1,557 sequelize/sequelize Code Issues 676 Pull requests 59 Projects 0 Wiki Pulse Graphs New issue https://github.com/sequelize/sequelize/issues/3220 Keep getting unique validation error: How to allow duplicate entries in N:M (belongsToMany)? #3220 Open maplesap opened this Issue Feb 25, 2015 · 22 comments Projects None yet Labels feature Milestone No milestone Assignees No one assigned 11 participants maplesap commented Feb 25, 2015 The unique validation check is preventing me from creating duplicate entries in my join table: // models/user.js User.belongsToMany(models.item, { foreign key through: models.history, as: "Owners', foreignKey: { name: "itemId", allowNull: true, unique: false } }); // models/item.js Item.belongsToMany(models.user, { through: models.history, as: "Owned", foreignKey: { unique: false } }); // models/history.js id: { type: DataTypes.INTEGER, primaryKey: true, autoIncrement: true }, other: DataTypes.STRING When a user buys the same item again, resulting in duplicate combinations of itemId and userId in history table, sequelize will throw validation errors: error creating foreign { name: 'SequelizeUniqueConstraintError', message: 'Validation error', .... message: "userId" must be unique type: 'unique violation' .... message: "itemId" must be unique type: 'unique violation' But I have set unique: false on the foreignkeys, and have created a primaryKey for history table, so this validation error confused me. What's the proper way to allow duplicate entries in N:M? sequelize member mickhansen commented Feb 25, 2015 unique entries in N:M is currently not supported. You can use unique: false for the options on the N:M relation but it only gets you halfway there (the setters will not work ideally so you manually have to create entries). maplesap commented Feb 25, 2015 Can you explain further with what you mean "so you manually have to create entries". Right now to create the history, I just do: models.History.create({userId: user_id, itemId: item_id}); Which triggers the unique validation errors if a duplicate of userId and itemId already exists. Do you mean I should remove my belongsToMany relations on user and item models, and I should just manually create the join table like: // models/history.js id: { type: DataTypes.INTEGER, primaryKey: true, autoIncrement: true }, userId: DataTypes.INTEGER, itemId: DataTypes.INTEGER, other: DataTypes.STRING sequelize member