mariadb Laravel迁移表已正确创建,但contact_list表返回空集

oprakyz7  于 5个月前  发布在  其他
关注(0)|答案(1)|浏览(51)

所以,我正在使用Laravel 10.32.1,我试图将我的Laravel迁移表迁移到我的MariaDB服务器,虽然迁移过程确实有效,并且contact_list表确实创建了,而不是预期的结果,这将导致表被填充这样的列,(注意,这是一个contact_list表的部分模拟,如果他们实际上工作,我不能适应其余的,因为宽度限制)

+----+------------+-----------+---------------+--------------+------+---------+-------+------------+-
| id | first_name | last_name | email_address | phone_number | note | address | photo | timestamps |                             
+----+------------+-----------+---------------+--------------+------+---------+-------+------------+-

字符串
但我却得到了

Empty set (0.070 sec)


. contact_list表如何返回空集而不是上面预期的表列?
我试着做sudo php artisan migrate:fresh(是的,我必须使用sudo,我不小心安装了MariaDB作为root,我也在WSL上使用Ubuntu 22.04),它删除了我的contact数据库中所有现有的表,并再次运行migrate命令,但是,运行命令后,然后输入MariaDB contact数据库,并运行select * from contact_list我仍然遇到了这个问题:

MariaDB [contact]> select * from contact_list;
Empty set (0.070 sec)


然后我试着看看其他迁移是否也遇到了这个问题,所以我尝试了select * from users,惊喜!它也吐出了完全相同的消息:

MariaDB [contact]> select * from users;
Empty set (0.007 sec)


这是我的contact数据库中的内容:

MariaDB [contact]> show tables;
+------------------------+
| Tables_in_contact      |
+------------------------+
| contact_list           |
| failed_jobs            |
| migrations             |
| password_reset_tokens  |
| personal_access_tokens |
| users                  |
+------------------------+
6 rows in set (0.001 sec)


这感觉有点奇怪,因为2014_10_12_000000_create_users_table.php2023_11_20_054223_create_contact_table.php都有代码来创建上述表。
2014_10_12_000000_create_users_table.php

<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

use function Laravel\Prompts\table;

return new class extends Migration
{
public function up(): void
    {
        Schema::create('users', function (Blueprint $table) {
            $table->id();
            $table->string('name');
            $table->string('email')->unique();
            $table->timestamp('email_verified_at')->nullable();
            $table->string('password');
            $table->rememberToken();
            $table->timestamps();
        });
    }
public function down(): void
    {
        Schema::dropIfExists('users');
    }
};


2023_11_20_054223_create_contact_table.php

<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

use function Laravel\Prompts\table;

return new class extends Migration
{
public function up(): void
    {
        Schema::create('contact_list', function (Blueprint $table) {
            $table->id();
            $table->string('first_name',24);
            $table->string('last_name',24);
            $table->string('email_address'); 
            $table->string('phone_number',16);
            $table->string('note',200);
            $table->string('address',50);
            $table->string('photo',100);
            $table->timestamps();
            $table->softDeletes();
        });
    }
public function down(): void
    {
        Schema::dropIfExists('contact_list');
    }
};


在所有这些之后,我试图在Stack Overflow上搜索答案,但这些问题中有许多是老的Laravel v5.x问题。感觉我的数据库或迁移方案有问题。我不知道,只是感觉无法解决。

ggazkfy8

ggazkfy81#

看起来您正在将迁移和播种任务合并到一个概念中。
迁移(通常)只负责创建或更新数据库方案和结构,而不负责填充数据。
填充数据(通常)通过播种执行。
当在本地工作时,这种区别可能看起来不重要,但是当您想要为本地环境(测试环境和生产环境)提供不同的默认数据时,将迁移与播种分开是很有用的。

相关问题