علیرضا
2 سال پیش توسط علیرضا مطرح شد
1 پاسخ

ارmigrate در لاراول

سلام و وقت بخیر بنده در دیتابیس دستور php artisan migrate:rollback میزنم و بعد این دستور میزنم php artisan migrate
که به ارور زیر بر می خورم مفهوم ارور چیه و راه حل چیست؟

  SQLSTATE[42S01]: Base table or view already exists: 1050 Table 'attributes' already exists (SQL: create table `attributes` (`id` bigint unsigned not null auto_in
crement primary key, `name` varchar(255) not null) default character set utf8mb4 collate 'utf8mb4_unicode_ci')

  at C:\Users\AsemaN\Desktop\AryaBMS\vendor\laravel\framework\src\Illuminate\Database\Connection.php:712
    708▕         // If an exception occurs when attempting to run a query, we'll format the error
    709▕         // message to include the bindings with SQL, which will make this exception a
    710▕         // lot more helpful to the developer instead of just the database's errors.
    711▕         catch (Exception $e) {
  ➜ 712▕             throw new QueryException(
    713▕                 $query, $this->prepareBindings($bindings), $e
    714▕             );
    715▕         }
    716▕     }

  1   C:\Users\AsemaN\Desktop\AryaBMS\vendor\laravel\framework\src\Illuminate\Database\Connection.php:501
      PDOException::("SQLSTATE[42S01]: Base table or view already exists: 1050 Table 'attributes' already exists")

مفهوم خط 2 هم میشه توضیح بدید
و یه سوال دیگه
User::find
User::query()->find
تفاوت داره؟


ثبت پرسش جدید
محمد رضا
تخصص : Full Stack Developer
@salar.mohammad2013 2 سال پیش مطرح شد
0

سلام دوست عزیز
خطا داره میگه این جدولی که میخوایی بسازیش (attributes) از قبل وجود داره و نمیشه دوباهره با همین نام جدول رو ساخت.
این مشکل معمولا زمانی پیش میاد که توی یک migration ایجاد شده چندین جدول مرتبط به هم رو زیر هم ایجاد میکنی
و هیچ اشکالی نداره این کار
فقط موضوعی که هست به صورت پیشفرض دیک اسامی جداول دیگت برای drop کردن نوشته نمیشه
راه حل سادست اول
توی بخشی که attributes رو ایجاد کردی برو در متد down مثل خود لاراول نام این جدول رو قرار بده
برای همه ی جداولت و migration هات چک کن این موضوع رو
حالا باید به صورت دستی attributes رو از دیتابیس پاک کنی و یک بار migtate رو اجرا کنی تا جدولت دوباره ایجاد بشه
حالا rollback هم کار خواهد کرد واست


برای ارسال پاسخ لازم است وارد شده یا ثبت‌نام کنید

ورود یا ثبت‌نام