Mam kilka migracji w nowym projekcie Laravel 4. Jedna dotyczy regionów, a druga obszarów. Każdy region ma wiele obszarów, a obszary należą do regionów.Laravel 4 Migracje rzucające 1072 błąd
Użyłem Laravel 4 i funkcji migracji przy wielu okazjach, ale nigdy wcześniej nie spotkałem się z tym problemem. Kiedy uruchamiam php artisan migrate:install
następnie php artisan migrate
pojawia się następujący błąd:
$ php artisan migrate
[Exception]
SQLSTATE[42000]: Syntax error or access violation: 1072 Key column 'region_
id' doesn't exist in table (SQL: alter table `areas` add constraint areas_r
egion_id_foreign foreign key (`region_id`) references `regions` (`id`)) (Bi
ndings: array (
))
migrate [--bench[="..."]] [--database[="..."]] [--path[="..."]] [--package[="...
"]] [--pretend] [--seed]
// Migracja regiony
class CreateRegionsTable extends Migration {
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
// Creates the regions table
Schema::create('regions', function($table)
{
$table->engine = 'InnoDB';
$table->increments('id');
$table->string('name', 160)->unique();
$table->timestamps();
});
}
}
// Migracja obszary
class CreateAreasTable extends Migration {
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
// Creates the cemeteries table
Schema::create('areas', function($table)
{
$table->engine = 'InnoDB';
$table->increments('id');
$table->foreign('region_id')->references('id')->on('regions');
$table->string('name', 160)->unique();
$table->timestamps();
});
}
}
Ah, to interesujące. Więc $ table-> foreign ('columnname') ... nie tworzy kolumny opartej na liczbach całkowitych, jeśli jeszcze nie istnieje? – JasonMortonNZ
To wszystko. Po prostu tworzy relację między tabelami. –
To rozwiązuje błąd, który otrzymałem, ale zastąpiło go innym. [Wyjątek] SQLSTATE [HY000]: Błąd ogólny: 1005 Nie można utworzyć tabelę 'NZF-org # sql-107c_ c8' (errno: 150) (SQL: alter table 'areas' dodać ograniczenie areas_region_id_f oreign klucz obcy ('region_id') odnosi się do' regionów' ("id")) (Wiązania: ar ray ( )) – JasonMortonNZ