0
votes

I think everything i wrote correctly.When i run "php artisan migrate" command PDOException appear.I went through all over relevant post in stackoverflow.But i am not getting any solution.

enter image description here

[PDOException] SQLSTATE[HY000]: General error: 1005 Can't create table laravel_jobs.#sql- ec4_170 (errno: 150 "Foreign key constraint is incorrectly formed")

4
What is the storage engine? myISAM or INNODB? Because myISAM doesn't support foreign key restraints. - Ron van der Heijden

4 Answers

2
votes

The error: Can't create table laravel_jobs

So I don't think the problem is with the Resume table migration.

1
votes

I think you need to update your migration code like :

Schema::create('resume', function (Blueprint $table) {
            $table->engine = 'InnoDB';
            $table->increments('id')->unsigned()->index();
            $table->integer('user_id')->unsigned();
            $table->foreign('user_id')->references('id')->on('users')->onDelete('cascade');
            $table->timestamp();
});

Hope this work for you!

0
votes

you should create your foreign keys after creating the table. like this:

public function up()
    {
        Schema::enableForeignKeyConstraints();

        Schema::create('user', function (Blueprint $table) {
            $table->engine = 'InnoDB';
            $table->uuid('id');
            $table->primary('id');
            $table->string('class_code');
            $table->string('username')->nullable();
            $table->string('email_address')->nullable();
            $table->uuid('contact_id')->nullable();
            $table->uuid('customer_id')->nullable();
            $table->char('password_hash', 64)->nullable();
            $table->boolean('active')->nullable();
            $table->string('remember_token', 100)->nullable();
            $table->timestamps();
        });

        Schema::table('user', function(Blueprint $table) {
            $table->foreign('contact_id')->references('id')->on('contact')->onDelete('cascade')->onUpdate('cascade');
            $table->foreign('customer_id')->references('id')->on('customer')->onDelete('cascade')->onUpdate('cascade');
        });
    }

you may however need to ensure the order that your migrations are ran is correct. Therefore you may want your create table function to create nullable foreign keys.

0
votes

Check the following terms:

1. The datatype of id column on users table and user_id on resume table are same.
2. If id is unsigned integer or big integer then user_id will be unsigned 
   integer or big integer.
3. Length of id on users table and user_id on resume table will be same.

Hope this solves your problem.