Я использую фреймворк Laravel, и я пытаюсь перенести некоторые файлы в базу данных (phpmyadmin), но я получаю эту ошибку: [Illuminate \ Database \ QueryException] SQLSTATE [HY000]: Общая ошибка: 1005 Невозможно создать таблицу 'лоха # SQL-38f_25f. (Errno: 150) (SQL: изменить таблицу encomenda
добавить C onstraint encomenda_username_foreign внешнего ключа (username
) ссылается users
(username
))Laravel SQL Не удается создать таблицу
Это мой стол "encomenda":
В сообщении об ошибке говорится, что он не может создать таблицу loja, но нет, где в этом файле есть ссылка на «loja». Я действительно хочу, чтобы создать таблицу «лоха», и на всякий случай, вот код:
<?php
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class CreateLojaTable extends Migration {
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('loja', function($table)
{
$table->engine = 'InnoDB';
$table->primary('api_key');
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::drop('loja');
}
}
Пользователи таблица миграции:
<?php
use Illuminate\Database\Migrations\Migration;
class ConfideSetupUsersTable extends Migration {
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
// Creates the users table
Schema::create('users', function($table)
{
$table->engine = 'InnoDB';
$table->increments('id')->unsigned();
$table->string('username')->unique();
$table->string('email');
$table->string('password');
$table->string('confirmation_code');
$table->string('remember_token')->nullable();
$table->boolean('confirmed')->default(false);
$table->boolean('admin')->default(false);
$table->timestamps();
});
// Creates password reminders table
Schema::create('password_reminders', function($table)
{
$table->engine = 'InnoDB';
$table->string('email');
$table->string('token');
$table->timestamp('created_at');
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::drop('password_reminders');
Schema::drop('users');
}
}
И вот теперь моя таблица миграции «linhaItem» :
<?php
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class CreateLinhaItemTable extends Migration {
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('linhaItem', function($table)
{
$table->engine = 'InnoDB';
$table->increments('IDLinha')->unsigned();
$table->integer('IDDisco')->unsigned();
$table->integer('IDCarrinho')->unsigned();
$table->double('preco');
$table->integer('quantidade');
$table->foreign('IDDisco')->references('IDDisco')->on('disco')->onDelete('cascade');
$table->foreign('IDCarrinho')->references('IDCarrinho')->on('carrinho')-onDelete('cascade');
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::drop('linhaItem');
}
}
Кто-нибудь знает, что не так?
EDIT: Я добавил -> onDelete ('каскад') к внешнему ключу, но получаю ту же ошибку.
EDIT2: я добавил unsigned в столбец id в файле «encomenda», но теперь я все еще получаю ту же ошибку, но с миграцией таблицы «linhaItem».
У вас есть таблица 'users', уже созданная до создания' encomenda'? – Kestutis
@ Kestutis да. –
Пожалуйста, добавьте слишком медленную таблицу 'users' – Kestutis