My table 'sales_order_details' has the id
field as integer 'int(10)' with a default value 0
. I need to change it to be a primary auto-increment key in migration.
I tried in the following way :
public function up()
{
Schema::table('sales_order_details', function (Blueprint $table){
$table->integer('id')->default(NULL)->change();
$table->increments('id')->change();
});
}
public function down()
{
Schema::table('sales_order_details', function (Blueprint $table){
$table->dropPrimary('id')->change();
});
}
I get the following errors:
[Illuminate\Database\QueryException] SQLSTATE[42000]: Syntax error or access violation: 1075 Incorrect table def inition; there can be only one auto column and it must be defined as a key (SQL: ALTER TABLE sales_order_details CHANGE id id INT UNSIGNED AUTO_INCREM ENT NOT NULL)
[Doctrine\DBAL\Driver\PDOException] SQLSTATE[42000]: Syntax error or access violation: 1075 Incorrect table def inition; there can be only one auto column and it must be defined as a key
[PDOException] SQLSTATE[42000]: Syntax error or access violation: 1075 Incorrect table def inition; there can be only one auto column and it must be defined as a key
How to make the migration properly ? I am using version 5.4
default
andincrements
make problem if used together ? – Istiaque Ahmed