سلام دوستان وقتتون بخیر.
QueryException : SQLSTATE[HY۰۰۰]: General error: ۱۰۰۵ Can't create table `project`.`#sql-a۲c_f۹` (errno: ۱۵۰ "Foreign key constraint is incorrectly formed") (SQL: alt
constraint `articles_user_id_foreign` foreign key (`user_id`) references `users` (`id`) on delete cascade)
sktop\laravel۲\vendor\laravel\framework\src\Illuminate\Database\Connection.php:۶۶۴
an exception occurs when attempting to run a query, we'll format the error
sage to include the bindings with SQL, which will make this exception a
more helpful to the developer instead of just the database's errors.
(Exception $e) {
row new QueryException(
$query, $this->prepareBindings($bindings), $e
وقتی کد php artisan migrate رو میزنم این ارور میده.
public function up()
{
Schema::create('articles', function (Blueprint $table) {
$table->engine = 'InnoDB';
$table->bigIncrements('id');
$table->integer('user_id')->unsigned();
$table->foreign('user_id')->references('id')->on('users')->onDelete('cascade');
$table->string('title');
$table->string('slug');
$table->text('description');
$table->text('body');
$table->string('imageUrl');
$table->string('tags');
$table->integer('commentCount')->default(۰);
$table->integer('viewCount')->default(۰);
$table->timestamps();
});سلام
@mohsenmlm76
این خط رو پاک کنید از مایگریشن
$table->foreign('user_id')->references('id')->on('users')->onDelete('cascade');
زیر همین schema
Schema::table('articles', function($table)
{
$table->foreign('user_id')->references('id')->on('users')->onDelete('cascade');
});
این رو قرار بدید
از ورژن چند mysql داریداستفاده میکنید؟
نه درست نشد.متاسفانه
از ورژن 7.3.3 استفاده میکنم.اخرین ورژن xamp
شاید پاسخ شما همینجا باشد
در انتها قرار دادم ولی هنوز درست نشد.
دوستان حل شد ممنون از کمکتون در جدول users این کد روتغییر دادم ولی دلیلش رو متوجه نمیشم چرا تغییر دادم دیگ ارور نداد؟
$table->bigIncrements('id');
bigincrement بود به increment تبدیل کردم