hinzufügen Ich versuche, einen Nullable Fremdschlüssel des Char-Datentyps zu erstellen. Wenn ich den Migrationsbefehl ausführe. Ich erhalte den folgenden Fehler. Ich bin mir nicht sicher, wo ich falsch liege.Laravel 5.2 Migration: Kann keinen Fremdschlüssel von char Datentyp
[Illuminate\Database\QueryException] SQLSTATE[HY000]: General error: 1215 Cannot add foreign key constraint (SQL: alter table
levels
add constraintlevels_sample_type_id_foreign
foreign key (sample_type_id
) referencessample_types
(id
))[PDOException] SQLSTATE[HY000]: General error: 1215 Cannot add foreign key constraint
sind hier die Migration Dateiinhalte für Tabellen Ebene
public function up()
{
Schema::create('levels', function (Blueprint $table) {
$table->engine = 'InnoDB';
$table->char('id', 36)->unique();
$table->string('description')->nullable();
$table->char('sample_type_id', 36)->nullable();
$table->integer('order');
$table->timestamps();
$table->primary('id');
$table->foreign('sample_type_id')->references('id')->on('sample_types');
});
}
und für die sample_types Tabelle sind als
public function up()
{
Schema::create('sample_types', function (Blueprint $table) {
$table->engine = 'InnoDB';
$table->char('id', 36)->unique();
$table->string('name');
$table->timestamps();
$table->primary('id');
});
}
Welcher Typ ist die Spalte 'sample_types.id'? – miken32
Char der Größe 36 –
Ich bin ziemlich positiv, beide müssen vom gleichen Typ sein. Daher darf 'sample_type_id' nicht null sein. –