Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Database error when trying to upgrade fom 3.1 to 8 #526

Closed
rtfmfm opened this issue Jun 10, 2019 · 7 comments
Closed

Database error when trying to upgrade fom 3.1 to 8 #526

rtfmfm opened this issue Jun 10, 2019 · 7 comments

Comments

@rtfmfm
Copy link

rtfmfm commented Jun 10, 2019

Q A
Bug? yes
New Feature? no
Framework Laravel
Framework version 5.8
Package version 9.2
PHP version 7.2.19

Actual Behaviour

When I try to run php artisan migrate I'm getting the following errors:

  SQLSTATE[42000]: Syntax error or access violation: 1075 Incorrect table definition; there can be only one auto column and it must be defined as a key (SQL: ALTER TABLE audits CHANGE id id INT UNSIGNED A  
  UTO_INCREMENT NOT NULL COLLATE utf8_unicode_ci, CHANGE user_id user_id INT UNSIGNED DEFAULT NULL COLLATE utf8_unicode_ci)    
SQLSTATE[42000]: Syntax error or access violation: 1075 Incorrect table definition; there can be only one auto column and it must be defined as a key 
SQLSTATE[42000]: Syntax error or access violation: 1075 Incorrect table definition; there can be only one auto column and it must be defined as a key

Expected Behaviour

Successful migration

Steps to Reproduce

just run php artisan migrate

@rtfmfm
Copy link
Author

rtfmfm commented Jun 13, 2019

I'm still stuck here... Can you help me, please?

@ting5875
Copy link

do u edit ur migration file? can u show it?

@rtfmfm
Copy link
Author

rtfmfm commented Jun 17, 2019

Hello! Thank you for your reply!

<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Schema;

class UpdateAuditsTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::table('audits', function (Blueprint $table) {
            $table->increments('id')->change();
            $table->renameColumn('type', 'event');
            $table->renameColumn('old', 'old_values');
            $table->renameColumn('new', 'new_values');
            $table->unsignedInteger('user_id')->nullable()->change();
            $table->string('user_type')->nullable();
            $table->renameColumn('route', 'url');
            $table->string('user_agent')->nullable();
            $table->string('tags')->nullable();
            $table->timestamp('updated_at')->nullable();
        });

        // Set the user_type value and keep the timestamp values.
        DB::table('audits')->update([
            'user_type'  => \App\User::class,
            'created_at' => DB::raw('created_at'),
            'updated_at' => DB::raw('updated_at'),
        ]);
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        // There's no turning back
    }
}

@ting5875
Copy link

ting5875 commented Jun 17, 2019

can u try to edit this:
$table->unsignedInteger('user_id',false,true)->nullable()->change();

@rtfmfm
Copy link
Author

rtfmfm commented Jun 17, 2019

Just tried. Got the same errors.

@looksystems
Copy link

Looks like these issues:
doctrine/dbal#3714
laravel/framework#30539

I used DB::unprepared() as a workaround in laravel 5.7.

@MortenDHansen
Copy link
Contributor

I hope the issue has resolved. Sorry for the late update 🙂

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants