Pro*_*eAL 0 php migration database-migration laravel laravel-8
我正在使用 Laravel 8。我正在尝试创建一个新表,但该表在数据库中不存在,并且没有任何其他同名表。我进行了迁移,这是迁移代码:
\n<?php\n\nuse Illuminate\\Database\\Migrations\\Migration;\nuse Illuminate\\Database\\Schema\\Blueprint;\nuse Illuminate\\Support\\Facades\\Schema;\n\nclass CreateCertificateTable extends Migration\n{\n /**\n * Run the migrations.\n *\n * @return void\n */\n public function up()\n {\n Schema::table('certificate', function (Blueprint $table) {\n $table->id();\n $table->unsignedBigInteger('user_id');\n $table->unsignedBigInteger('vac_id');\n $table->time('last_shot_date');\n $table->timestamps();\n\n $table->foreign('user_id')->references('id')->on('users');\n $table->foreign('vac_id')->references('id')->on('vaccination');\n });\n }\n\n /**\n * Reverse the migrations.\n *\n * @return void\n */\n public function down()\n {\n Schema::table('certificate', function (Blueprint $table) {\n //\n });\n }\n}\n\nRun Code Online (Sandbox Code Playgroud)\n做完之后
\nphp artisan migrate\nRun Code Online (Sandbox Code Playgroud)\n这是我收到的完整错误消息:
\n Illuminate\\Database\\QueryException\n\n SQLSTATE[42S02]: Base table or view not found: 1146 Table 'vaccinationappointme\nnts.certificate' doesn't exist (SQL: alter table `certificate` add `id` bigint un\nsigned not null auto_increment primary key, add `user_id` bigint unsigned not nul\nl, add `vac_id` bigint unsigned not null, add `last_shot_date` time not null, add\n `created_at` timestamp null, add `updated_at` timestamp null)\n\n at D:\\xampp\\htdocs\\Vaccination_Appointments\\vendor\\laravel\\framework\\src\\Illumi\nnate\\Database\\Connection.php:692\n 688\xe2\x96\x95 // If an exception occurs when attempting to run a query, we'll\nformat the error\n 689\xe2\x96\x95 // message to include the bindings with SQL, which will make thi\ns exception a\n 690\xe2\x96\x95 // lot more helpful to the developer instead of just the databas\ne's errors.\n 691\xe2\x96\x95 catch (Exception $e) {\n \xe2\x9e\x9c 692\xe2\x96\x95 throw new QueryException(\n 693\xe2\x96\x95 $query, $this->prepareBindings($bindings), $e\n 694\xe2\x96\x95 );\n 695\xe2\x96\x95 }\n 696\xe2\x96\x95\n\n \xe2\x80\xa2 A table was not found: You might have forgotten to run your migrations. You c\nan run your migrations using `php artisan migrate`.\n https://laravel.com/docs/master/migrations#running-migrations\n\n 1 D:\\xampp\\htdocs\\Vaccination_Appointments\\vendor\\laravel\\framework\\src\\Illum\ninate\\Database\\Connection.php:485\n PDOException::("SQLSTATE[42S02]: Base table or view not found: 1146 Table '\nvaccinationappointments.certificate' doesn't exist")\n\n 2 D:\\xampp\\htdocs\\Vaccination_Appointments\\vendor\\laravel\\framework\\src\\Illum\ninate\\Database\\Connection.php:485\n PDOStatement::execute()\n\nRun Code Online (Sandbox Code Playgroud)\n我曾尝试这样做:
\nphp artisan migrate:refresh\nRun Code Online (Sandbox Code Playgroud)\n仍然是同样的问题。我没有使用过模型。
\n如果你想创建一个带有迁移的表,你需要使用::create()而不是::table()
::table()函数尝试改变你的表
| 归档时间: |
|
| 查看次数: |
1753 次 |
| 最近记录: |