0

I have a problem where the generated seed for SQL Server 2012 outputs this error

[Illuminate\Database\QueryException]
 SQLSTATE[22001]: [Microsoft][SQL Server Native Client 11.0][SQL Server]Stri
 ng or binary data would be truncated. (SQL: insert into [books] ([judul], [
 pengarang], [dcc_code], [penerbit], [isbn], [tahun], [updated_at], [created
 _at]) values (Problem solving with the programmable calculator : puzzle, ga
 mes & simulation with math & science application, David L. Dunlop  Thomas F
 . Sigmund, 510.285, Prentice Hall, 0574213201, 1983, 2015-01-26 03:30:19.00
 0, 2015-01-26 03:30:19.000))'

Even though I've made sure I set my schema to contain the data correctly

    Schema::create('books', function(Blueprint $table)
    {
        $table->engine="INNODB";
        $table->increments('id');
        $table->text('judul');
        $table->string('pengarang', 200);
        $table->string('dcc_code', 20);
        $table->string('penerbit', 100);
        $table->string('edisi', 100)->nullable();
        $table->string('tahun', 10);
        $table->string('isbn', 100)->nullable();
        $table->string('book_image_name', 200)->nullable();

        //Unique to Perpustakaan
        $table->string('call_number', 100)->nullable();
        $table->float('rating_cache')->default('0');
        $table->integer('rating_count')->default('0');
        $table->timestamps();
    });

Here's the seed

    Book::create( 
        array(
            'judul' => "Problem solving with the programmable calculator : puzzle, games & simulation with math & science application",
            'pengarang' => "David L. Dunlop  Thomas F. Sigmund",
            'dcc_code' => "510.285",
            'penerbit' => "Prentice Hall",
            'isbn' => "0574213201",
            'tahun' => "1983"
        )
    );

Any help or hint would be appreciated! :)

Per @patricus hint, I found out that the generated column in SQL Server is only nvarchar(100) rather than nvarchar(300). Even though I've changed the type into longText in migrations, the generated column still is nvarchar(100)

Willy Pt
  • 1,795
  • 12
  • 20
  • 1
    Are you sure that is the right migration? It has the line `$table->engine="INNODB";` which is specific to MySQL, not SQL Server. Can you show the actual field definitions? Do they line up with the migration file provided? – patricus Jan 26 '15 at 05:11
  • $table->engine = "INNODB" will do nothing when being exposed on SQL Server... So the migration works. The current solution was to deploy on MySQL which (fortunately) doesn't have the recurring problem – Willy Pt Jan 26 '15 at 05:14
  • @patricus I just realized that the generated column is nvarchar (100) character length. It's funny consider I put 200 on the string length. Thanks for the lead! :) – Willy Pt Jan 26 '15 at 05:20
  • It seems to be an issue with the datatype mapping of whatever client you're using. There is no such thing as a "string" data type in SQL Server nor is there such as thing as "long text". Please double check the compatibility of the client you're using to develop this, for SQL Server. –  Jan 26 '15 at 05:55

0 Answers0