Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
295 views
in Technique[技术] by (71.8m points)

"Syntax error or access violation: 1064" When changing column type from string to integer [LARAVEL MIGRATION]

In the down() function of my migration i have the following line:

 $table->integer('placeholder')->change();

Here I try to change the column type 'number' from string(750 characters) to integer. Whenever I try to run this rollback, I get hit with:

SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax

This also happens when I try to change the column to something else (such as a boolean). Setting the amount of characters from 750 to 191, so: $table->string('placeholder',191)->change(); does work.

The table I'm working in currently does not contain any data & i'm using the utf8mb4 character-set

question from:https://stackoverflow.com/questions/65888900/syntax-error-or-access-violation-1064-when-changing-column-type-from-string-t

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Are you sure your column name is number? It is a keyword in mysql and such column names cannot be used unless you quote it like `number`. It is not a good practice to use such keywords as a column name.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...