Bowis
Bowis

Reputation: 632

"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

Upvotes: 0

Views: 408

Answers (2)

Sergey Zakharevich
Sergey Zakharevich

Reputation: 390

Perhaps in the current table you have filled in the column 'placeholder' that does not correspond to the new rules of this column.

  1. Create a migration with new temporary column $ table-> string ('temp_placeholder', 191)
  2. Write a seeder to transfer data from the 'placeholder' column to 'temp_placeholder', taking into account the new specified rules for the column.
  3. Create a migration to delete the 'placeholder' column and rename the 'temp_placeholder' column to 'placeholder'

Upvotes: 1

SASM
SASM

Reputation: 1312

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.

Upvotes: 2

Related Questions