cesargb / laravel-magiclink

Create link for authenticate in Laravel without password or get private content
MIT License
383 stars 44 forks source link

Unable to create or change a table without a primary key #65

Closed kb6673 closed 2 years ago

kb6673 commented 2 years ago

We have a Managed MySQL Server with DigitalOcean. In it's default config it comes with system variable 'sql_require_primary_key` set. This prevents us running migrations with the following error

Migrating: 2017_07_06_000000_create_table_magic_links

   Illuminate\Database\QueryException 

  SQLSTATE[HY000]: General error: 3750 Unable to create or change a table without a primary key, when the system variable 'sql_require_primary_key' is set. Add a primary key to the table or unset this variable to avoid this message. Note that tables without a primary key can cause performance problems in row-based replication, so please consult your DBA before changing this setting. (SQL: create table `magic_links` (`id` char(36) not null, `token` varchar(255) not null, `action` text not null, `num_visits` tinyint unsigned not null default '0', `max_visits` tinyint unsigned null, `available_at` timestamp null, `created_at` timestamp null, `updated_at` timestamp null) default character set utf8mb4 collate 'utf8mb4_unicode_ci')

My only fix was this inelegant solution - changing the migration file

 public function up()
    {
        Schema::create(config('magiclink.magiclink_table', 'magic_links'), function (Blueprint $table) {
            $table->bigIncrements( 'iid' );
            $table->uuid('id');
            $table->string('token', 255);
            $table->text('action');
            $table->unsignedTinyInteger('num_visits')->default(0);
            $table->unsignedTinyInteger('max_visits')->nullable();
            $table->timestamp('available_at')->nullable();
            $table->timestamps();

        });
    }

Other migrations run as expected - just this one.

Any suggestions?

cesargb commented 2 years ago

This issue is related with: https://github.com/laravel/framework/issues/33238 (Laravel only create pk inline in auto increments fields)

Optionally, you can disable sql_require_primary_key in session of the migration.

But perhaps the best options is modify this package to convert the PK at auto Increment. This change require a new mayor release.

kb6673 commented 2 years ago

Totally missed that related issue, Looks like that is the cause of this,