当在Laravel中加载数据时,它说NVarchar数据类型没有转换为DateTime数据类型

问题描述 投票:0回答:1
public function up(): void
    {
        Schema::create('books', function (Blueprint $table) {
            $table->id();
            $table->string('book_name');
            $table->string('author');
            $table->integer('page_count');
            $table->foreignId('category_id')->constrained()->onDelete('cascade');
            $table->string('isbn');
            $table->string('publisher');
            $table->string('publish_year');
            $table->string('status');
            $table->timestamps();
        });
    }

SQLSTATE[22007]:[Microsoft] [SQL Server的ODBC驱动程序17] [SQL Server] VARCHAR数据类型向DateTime数据类型的转换导致了偏外值。 (连接:SQLSRV,SQL:插入[书]([book_name],[作者],[page_count],[category_id],[isbn],[Publisher],[Publish_year],[status_year],[status],[updated_at],[inpeated_at],[creats_at])值1949年,可用,2025-03-17 14:01:33.722,2025-03-17 14:01:33.722))

我正在网站上工作,但是在尝试使用Seeder添加数据时,我总是会遇到相同的错误。我尝试使用DateTime而不是时间戳,尽管我使其无效,但它仍然会出现相同的错误。我使用SQL Server ManagementStudio.

php sql-server laravel database-migration laravel-seeder
1个回答
0
投票
我会考虑另一个解决方案:

首先使

published_year

成为整数类型,因此:

$table->integer('publish_year');
thin,我本来会尝试在播种机中手动添加
created_at

updated_at


最新问题
© www.soinside.com 2019 - 2025. All rights reserved.