Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

abkrim's avatar
Level 13

Issues when use a model without id

I use a model without id for compatiblity of software

class Domain extends Model
{
    use SoftDeletes, CascadeSoftDeletes;

    protected $cascadeDeletes = ['mailboxes'];

    protected $primaryKey = 'domain';

    protected $keyType = 'string';

    public $incrementing = false;

When try use with delete, softdelete , get error

[previous exception] [object] (PDOException(code: 22007): SQLSTATE[22007]: Invalid datetime format: 1366 Incorrect integer value: 'villegas.net' for column `albaridnova`.`action_events`.`actionable_id` at row 1 at /home/abkrim/Sites/albaridnova/vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/PDOStatement.php:121)
[stacktrace]

Any body know issues for this question?

0 likes
4 replies
abkrim's avatar
Level 13
<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class CreateDomainsTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('domains', function (Blueprint $table) {
            $table->string('domain')->unique();
            $table->unsignedInteger('user_id')->nullable(false)
                ->comment('Albarid for best performance with relations tables');
            $table->text('description')->nullable();
            $table->text('disclaimer')->nullable();
            $table->unsignedInteger('aliases')->nullable(false)->default(0);
            $table->unsignedInteger('mailboxes')->nullable(false)->default(0);
            $table->unsignedInteger('maillists')->nullable(false)->default(0);
            $table->unsignedInteger('quota')->nullable(false)->default(0)->comment('Real quota asigned in Mb');
            $table->unsignedInteger('max_quota')->nullable(false)->default(0)->comment('Grace quota asigned in Mb');
            $table->unsignedBigInteger('quota_used')->nullable(false)->default(0)->comment('Quota used in Bytes');
            $table->unsignedInteger('quota_user_default')->nullable(false)->default(1024)
                ->comment('QUota default mailbox in Megabytes');
            $table->string('transport')->nullable(false)->default('dovecot');
            $table->boolean('backupmx')->nullable(false)->default(false)->index();
            // $table->json('settings')->nullable();
            $table->boolean('active')->nullable(false)->default(true)->index();
            $table->timestamps();
            $table->softDeletes();
            $table->timestamp('expires_in')->nullable(true)->index();
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('domains');
    }
}

Sinnbeck's avatar

Looks fine. I assume it works if you disable CascadeSoftDeletes?

abkrim's avatar
Level 13

A lot of thanks for your effort. After this problems, I get way for add id to tables without id, and refactor app and mother app. Is more easy for me.

Best regards.

Please or to participate in this conversation.