Welcome Guest, Not a member yet? Register   Sign In
Migrate spark with Foreigner key table show (Can't create table `fk`.`employees` (err
#1

(This post was last modified: 11-06-2022, 06:28 AM by luckmoshy.)

Hi guys, I recently faced this issue I normally create my foreigner key table in the same migration file but now have decided to make two separate migration files unfortunately get this error in the spark command (Can't create table `fk`.`employees` (errno: 150 "Foreign key constraint is incorrectly formed")

The question does  CI 4 spark command not accept two different migration files?

Spark command it does not accept two different files like:
1.class CreateEmployeesTable extends Migration
2class CreateDepartmentsTable extends Migration



It accepts only one file
PHP Code:
<?php

namespace App\Database\Migrations;

use 
CodeIgniter\Database\Migration;

class 
CreateDepartmentsTable extends Migration
{
    public function up() {
 
//departments
          $this->forge->addField([
            'id' => ['type' => 'INT','constraint' => 5,'unsigned' => true,'auto_increment' => true,],
            'name' => ['type' => 'VARCHAR','constraint' => '100',]
          ]);
          $this->forge->addKey('id'true);
          $this->forge->createTable('departments');
 
  
 
   
//employees   
 
  $this->forge->addField([
          'id' => ['type' => 'INT','constraint' => 5'unsigned' => true'auto_increment' => true,],
 
  'depart_id' => [ 'type' => 'INT''constraint' => 5,'unsigned' => true,],
          'name' => ['type' => 'VARCHAR','constraint' => '100',]
      ]);

      $this->forge->addKey('id'true);
      $this->forge->addForeignKey('depart_id''departments''id''CASCADE''CASCADE');
      $this->forge->createTable('employees');
    }

    public function down() {
        $this->forge->dropTable('departments');
 
$this->forge->dropTable('employees');

    }

Codeigniter First, Codeigniter Then You!!
yekrinaDigitals

Reply


Messages In This Thread
Migrate spark with Foreigner key table show (Can't create table `fk`.`employees` (err - by luckmoshy - 11-06-2022, 06:24 AM



Theme © iAndrew 2016 - Forum software by © MyBB