Undefined table: 7 ERROR: relation "users" does not exist
Undefined table: 7 ERROR: relation "users" does not exist
朋友们,我在使用 postgres 进行 laravel 迁移时遇到以下问题,当我对迁移进行更改时,在本例中是用户 table,但我在尝试删除一个键的索引,你能帮我解决这个问题吗?
这是我的迁移代码:
public function up() {
Schema::create('users', function (Blueprint $table) {
$table->id();
$table->integer('idProfile');
$table->string('name');
$table->string('surname');
$table->string('email')->unique();
$table->string('photo')->nullable();
$table->timestamp('email_verified_at')->nullable();
$table->string('password');
$table->rememberToken();
$table->timestamps();
});
}
public function down() {
Schema::dropIfExists('users');
Schema::table('users', function (Blueprint $table){
$table->dropPrimary('id');
$table->dropIndex('users_pkey');
});
}
来自我的控制台的响应:
这些是列出我的索引:
这是最后的结构table:
评论,需要改进的地方我洗耳恭听
强烈建议不要更改迁移文件...
如果你需要向你的 table 添加一个新行(假设你有 mytable 并且你想将 myrow 添加到 table),你可以在终端中写入:
php artisan make:migration add_myrow_to_mytable_table
之后,编辑新添加的迁移文件!
记得在down function中添加如下代码:
Schema::table('mytable', function (Blueprint $table) {
$table->dropColumn('myrow');
});
毕竟,运行 :
php artisan migrate
如果您想从 table 中删除一列,只需按照以下操作即可:
当你是运行migrate:refresh
时,你就是运行down方法。在你的 down 方法中,你正在删除 table,然后尝试对其进行编辑,这就是你得到“用户”不存在的原因。
如果这只是在开发环境中,请在 up 方法中进行更改,并从 down 方法中删除 dropIFExists()
以外的所有内容。
朋友们,我在使用 postgres 进行 laravel 迁移时遇到以下问题,当我对迁移进行更改时,在本例中是用户 table,但我在尝试删除一个键的索引,你能帮我解决这个问题吗?
这是我的迁移代码:
public function up() {
Schema::create('users', function (Blueprint $table) {
$table->id();
$table->integer('idProfile');
$table->string('name');
$table->string('surname');
$table->string('email')->unique();
$table->string('photo')->nullable();
$table->timestamp('email_verified_at')->nullable();
$table->string('password');
$table->rememberToken();
$table->timestamps();
});
}
public function down() {
Schema::dropIfExists('users');
Schema::table('users', function (Blueprint $table){
$table->dropPrimary('id');
$table->dropIndex('users_pkey');
});
}
来自我的控制台的响应:
这些是列出我的索引:
这是最后的结构table:
评论,需要改进的地方我洗耳恭听
强烈建议不要更改迁移文件... 如果你需要向你的 table 添加一个新行(假设你有 mytable 并且你想将 myrow 添加到 table),你可以在终端中写入:
php artisan make:migration add_myrow_to_mytable_table
之后,编辑新添加的迁移文件! 记得在down function中添加如下代码:
Schema::table('mytable', function (Blueprint $table) {
$table->dropColumn('myrow');
});
毕竟,运行 :
php artisan migrate
如果您想从 table 中删除一列,只需按照以下操作即可:
当你是运行migrate:refresh
时,你就是运行down方法。在你的 down 方法中,你正在删除 table,然后尝试对其进行编辑,这就是你得到“用户”不存在的原因。
如果这只是在开发环境中,请在 up 方法中进行更改,并从 down 方法中删除 dropIFExists()
以外的所有内容。