I am working on a dashboard for my team, that allows to get information on our projects. When creating a new project in the dashboard, the user must fill a form with the name, starting date and closing date of the project. However, I have an issue when inserting a project that has a name already existing in database, and I am not able to find a solution as each project has its own index (with an auto-incremented integer column in DB), and the project name column is not a primary key of the table. It works perfectly when using a different name, for example if "project summer" is in DB, inserting "project summer" will fail (leading to an error 502) but "project summer 2" will not. How can I insert new projects with similar names?
I am using NodeJS with express, ajax and request, and my database uses mySQL managed with PHPMyAdmin.
EDIT (03/12/2018): "Name" column appears to be a table index. What can be the consequences on the table if I edit the column to not act as an index anymore?
答案 0 :(得分:1)
Can you post a snip of your schema ? Without looking at your code it might be tough to see what your mappings are
Edit: I think “key” and “index” in MySQL mean the same thing. You can only have have 1 primary key and it looks like you have one above. Try and remove the index from the name table
答案 1 :(得分:0)
MySQL保留字。 MySQL中的保留字不能用作标识符(表或列名等。),除非用引号引起来( `)。标识符的引用是在 MySQL 3.23.6 版本中引入的。
如果以 ANSI 模式运行MySQL,还可以用双引号(“)括起来。您可以像这样使用它:
Insert into `tablename` (`name`) VALUES ("xyz");