ターミナル $ php artisan make:migration create_posts_table
上記コマンドでてテーブルcreate行い
migrationファイルに追記してphp artisan migrateした際にエラーが出る
<?php use Illuminate\Database\Migrations\Migration; use Illuminate\Database\Schema\Blueprint; use Illuminate\Support\Facades\Schema; class CreatePostsTable extends Migration { /** * Run the migrations. * * @return void */ public function up() { Schema::create('posts', function (Blueprint $table) { $table->bigIncrements('id'); $table->string('name'); $table->string('brand'); $table->string('image')->nullable(); $table->integer('user_id'); $table->timestamps(); }); } /** * Reverse the migrations. * * @return void */ public function down() { Schema::dropIfExists('posts'); } }
usersテーブルはすでにあるよとエラー出てますが
確かにusersテーブルはすでに作成しております。
しかし今回は、$ php artisan make:migration create_posts_tableでpostsテーブル作り
php artisan migrateを行いました
こ教授お願いします。
Illuminate\Database\QueryException : SQLSTATE[42S01]: Base table or view already exists: 1050 Table 'users' already exists (SQL: create table `users` (`id` bigint unsigned not null auto_increment primary key, `name` varchar(255) not null, `email` varchar(191) not null, `email_verified_at` timestamp null, `password` varchar(255) not null, `remember_token` varchar(100) null, `created_at` timestamp null, `updated_at` timestamp null) default character set utf8mb4 collate 'utf8mb4_unicode_ci') at /Users/MISIAN/projects/shop/vendor/laravel/framework/src/Illuminate/Database/Connection.php:669 665| // If an exception occurs when attempting to run a query, we'll format the error 666| // message to include the bindings with SQL, which will make this exception a 667| // lot more helpful to the developer instead of just the database's errors. 668| catch (Exception $e) { > 669| throw new QueryException( 670| $query, $this->prepareBindings($bindings), $e 671| ); 672| } 673| Exception trace: 1 PDOException::("SQLSTATE[42S01]: Base table or view already exists: 1050 Table 'users' already exists") /Users/MISIAN/projects/shop/vendor/laravel/framework/src/Illuminate/Database/Connection.php:463 2 PDOStatement::execute() /Users/MISIAN/projects/shop/vendor/laravel/framework/src/Illuminate/Database/Connection.php:463 Please use the argument -v to see more details.
satatus見たら一つもmigrateできてない状態です。
$ php artisan migrate:status +------+------------------------------------------------+-------+ | Ran? | Migration | Batch | +------+------------------------------------------------+-------+ | No | 2014_10_12_000000_create_users_table | | | No | 2014_10_12_100000_create_password_resets_table | | | No | 2019_08_19_000000_create_failed_jobs_table | | | No | 2020_03_01_181817_create_posts_table | | +------+------------------------------------------------+-------+
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。