【发布时间】:2021-01-29 03:49:36
【问题描述】:
我正在尝试向现有集合添加一列。我正在使用 MongoDB 我正在运行以下迁移:
<?php
use Illuminate\Database\Migrations\Migration;
class AddLocaleColumn extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('users', function ($table) {
$table->string('locale')->default(config('app.locale'));
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table('users', function ($table) {
$table->dropColumn('locale');
});
}
}
当我执行“php artisan migrate”时,我得到的响应很好:
php artisan migrate
Migrating: 2020_01_01_000000_add_locale_column
Migrated: 2020_01_01_000000_add_locale_column
当我去“robomongo 3t studio”验证新列是否已创建时,我看不到它
我错过了什么吗?我是 mongodb 和 laravel 的新手,我对我如此赤裸裸。
【问题讨论】:
-
乍一看一切正常...
DESCRIBE users是有效的 MongoDB 命令吗?那(或等效的,不知道 Mongo 语法抱歉)应该列出users表的列。 -
iam 也使用这个 mongodb 命令来检查新列是否存在: db.users.find({ 'locale' : { '$exists' : true }}).pretty();但这也会返回否定结果
-
嗯...嗯,我觉得一切正常。你确定你检查的是正确的数据库吗?如果你再次运行
php artisan migrate会发生什么? (应该说“无迁移”) -
是的,这正是我再次尝试时得到的结果
-
表示迁移成功。您在
SELECT * FROM migrations中看到迁移了吗?2020_01_01_000000_add_locale_column应该有一行(最近的)
标签: php laravel mongodb migration