MySQL Error 1060: Duplicate column name ALTER TABLE

ぃ、小莉子 提交于 2019-12-01 10:56:38

问题


I am having some problems with a query because of errors in the code that I did not create.

$query = $this->db->query("ALTER TABLE `" . DB_PREFIX . "customer` ADD `customer_type` TINYINT(1) NOT NULL; 

I'm not a coder, but have so far fixed (I think) the error. By comparing with other queries that don't throw errors and reading quite a few similar posts on stackoverflow, I added a missing quote, a parenthese, and semi-colon. No more error, but not sure if this is even the correct way of doing it? I ended up with this:

$query = $this->db->query("ALTER TABLE `" . DB_PREFIX . "customer` ADD `customer_type` TINYINT(1) NOT NULL;");

But now, I get a duplicate column error 1060 "duplicate column name". So I did the same thing, googled the heck out of it, search stackoverflow and found some examples using aliases and a bunch of extra lines of code which is way above my head. This code lives in side a .php file, would someone kindly hold my hand through this? You could consider it your good deed for the day! Thanks for your time.


回答1:


It means that the column already exists in your table, most likely the former programmer wanted to add the column and forgot to delete the query aftewrads.



来源:https://stackoverflow.com/questions/13736570/mysql-error-1060-duplicate-column-name-alter-table

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!