Laravel:表格添加还可以。但是当我想更新时会给我错误

发布于 2025-02-13 04:46:23 字数 1490 浏览 1 评论 0原文

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

又爬满兰若 2025-02-20 04:46:23

您将需要数据库中的Updated_at列,在迁移中添加此列:
$ table-> timestamps();
然后重新运行迁移

You will require updated_at column in your Database, add this in migration :
$table->timestamps();
then re run the migration

水染的天色ゝ 2025-02-20 04:46:23

如果要保存create_at和updated_at,则必须在迁移中设置此或手动添加。

您的迁移一定是这样的:

Schema::create('users', function (Blueprint $table) {
    $table->id();
    $table->string('email', 250)->unique();
    $table->string('password', 250);
    $table->string('mobile', 12)->nullable();
    $table->timestamp('mobile_verified_at')->nullable();
    $table->timestamp('email_verified_at')->nullable();
    $table->string('avatar', 100)->nullable();
    $table->rememberToken();
    $table->timestamps();  ----->>>>>>> Here is what I mean!
});

否则,无论何时创建/更新记录,您都必须在型号的顶部设置关注行使用之后之后命令):

public $timestamps = false;

If you want to save created_at and updated_at, you must to set this in you migration or add the manually.

Your migration must be soething like this:

Schema::create('users', function (Blueprint $table) {
    $table->id();
    $table->string('email', 250)->unique();
    $table->string('password', 250);
    $table->string('mobile', 12)->nullable();
    $table->timestamp('mobile_verified_at')->nullable();
    $table->timestamp('email_verified_at')->nullable();
    $table->string('avatar', 100)->nullable();
    $table->rememberToken();
    $table->timestamps();  ----->>>>>>> Here is what I mean!
});

Otherwise when it's no matter when your record is created/updated, you have to set following line at the top of your Model (after use command):

public $timestamps = false;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文