Open mrvx opened 4 years ago
same here
I have fixed this issue by using increment('id') instead of id() in 2014_10_12_000000_create_users_table.php file & I use $table->unsignedInteger('user_id'); instead of $table->integer('user_id')->unsigned(); in 2016_07_29_171118_create_chatter_discussion_table.php file
That did work however, now this error responds after changing the unsignedBigIntegers.
General error: 1005 Can't create table dashhound
.chatter_discussion
(errno: 121 "Duplicate key on write or update") (SQL: alter table chatter_discussion
add constraint chatter_discussion_chatter_category_id_foreign
foreign key (chatter_category_id
) references chatter_categories
(id
) on delete cascade)
That did work however, now this error responds after changing the unsignedBigIntegers.
General error: 1005 Can't create table
dashhound
.chatter_discussion
(errno: 121 "Duplicate key on write or update") (SQL: alter tablechatter_discussion
add constraintchatter_discussion_chatter_category_id_foreign
foreign key (chatter_category_id
) referenceschatter_categories
(id
) on delete cascade)
first you need to fresh database next use migrate
That did work however, now this error responds after changing the unsignedBigIntegers. General error: 1005 Can't create table
dashhound
.chatter_discussion
(errno: 121 "Duplicate key on write or update") (SQL: alter tablechatter_discussion
add constraintchatter_discussion_chatter_category_id_foreign
foreign key (chatter_category_id
) referenceschatter_categories
(id
) on delete cascade)first you need to fresh database next use migrate
I did manage to get it working eveentually, apologies for not updating the issue. I've since created my own due to it being a university project and looks good having my own.
Migrating: 2016_07_29_171118_create_chatter_post_table Migrated: 2016_07_29_171118_create_chatter_post_table (0.02 seconds) Migrating: 2016_07_29_171128_create_foreign_keys
Illuminate\Database\QueryException
SQLSTATE[HY000]: General error: 1005 Can't create table forum
.chatter_discussion
(errno: 150 "Foreign key constraint is incorrectly formed") (SQL: alter table chatter_discussion
add constraint chatter_discussion_user_id_foreign
foreign key (user_id
) references users
(id
) on delete cascade on update cascade)
at vendor/laravel/framework/src/Illuminate/Database/Connection.php:671 667| // If an exception occurs when attempting to run a query, we'll format the error 668| // message to include the bindings with SQL, which will make this exception a 669| // lot more helpful to the developer instead of just the database's errors. 670| catch (Exception $e) {
671| throw new QueryException( 672| $query, $this->prepareBindings($bindings), $e 673| ); 674| } 675|
+12 vendor frames
13 database/migrations/2016_07_29_171128_create_foreign_keys.php:17 Illuminate\Support\Facades\Facade::__callStatic()
+21 vendor frames
35 artisan:37 Illuminate\Foundation\Console\Kernel::handle()
<?php
use Illuminate\Database\Migrations\Migration; use Illuminate\Database\Schema\Blueprint;
class CreateChatterDiscussionTable extends Migration { public function up() { Schema::create('chatter_discussion', function (Blueprint $table) { $table->increments('id'); $table->integer('chatter_category_id')->unsigned()->default('1'); $table->string('title'); $table->unsignedInteger('user_id'); $table->boolean('sticky')->default(false); $table->integer('views')->unsigned()->default('0'); $table->boolean('answered')->default(0); $table->timestamps(); }); }
public function down()
{
Schema::drop('chatter_discussion');
}
}
help please ;(
Migrating: 2016_07_29_171128_create_foreign_keys
Illuminate\Database\QueryException : SQLSTATE[HY000]: General error: 1215 Cannot add foreign key constraint (SQL: alter table
chatter_discussion
add constraintchatter_discussion_user_id_foreign
foreign key (user_id
) referencesusers
(id
) on delete cascade on update cascade)at /Users/veikoteekel/PhpstormProjects/pillamail2/pillamail/vendor/laravel/framework/src/Illuminate/Database/Connection.php:664 660| // If an exception occurs when attempting to run a query, we'll format the error 661| // message to include the bindings with SQL, which will make this exception a 662| // lot more helpful to the developer instead of just the database's errors. 663| catch (Exception $e) {
Exception trace:
1 PDOException::("SQLSTATE[HY000]: General error: 1215 Cannot add foreign key constraint") /Users/veikoteekel/PhpstormProjects/pillamail2/pillamail/vendor/laravel/framework/src/Illuminate/Database/Connection.php:458
2 PDOStatement::execute() /Users/veikoteekel/PhpstormProjects/pillamail2/pillamail/vendor/laravel/framework/src/Illuminate/Database/Connection.php:458
Please use the argument -v to see more details.