Create Postgres "Numeric" Field in Laravel 5.1

Asked

Viewed 657 times

1

I need to create a field like Numeric existing in postgres using migrations from the Laravel, can anyone tell me how I do?

I tried that, but it didn’t roll:

public function up()
{
    Schema::create('complementos', function (Blueprint $table) {
        $table->increments('id');
        $table->numeric('comprimento');
        $table->timestamps();
    });
}

I need to store values like 50.00, with the decimal places so set keeping the zeros after the point. If it is not really possible to create the Numeric, what other kind I could use?

Error while running migrate:

[Symfony Component Debug Exception Fatalerrorexception]

Call to Undefined method Illuminate Database Schema Blueprint::Umeric ()

  • How you passed the 'length'?

  • I pass exactly like this: 50.00. but the float type and real simply do not consider the . 00, and store only the 50.

  • Try it like this $table->numeric('15,2');

  • this in "Schema::create"? And how do I define the field name?

  • Exactly, you need to pass the size and scale

  • postgres does not have innodb is all one engine only.

  • ok put as said, but returns the msm error.

  • What is the error message?

  • I put in the question @rray

  • Dude, Numeric() doesn’t exist, try bigInteger()

  • but if bigInteger does not accept 50.00, it error because of the point @Raphaelcaldas

  • you do not value, it already has a value and 8bytes if I am not mistaken, you use: $table->bigInteger('NAME');

  • Yes, I did that and it was created all right, the problem is that I can’t store data that contains punctuation in it.

  • Tell me the mistake you make, so I understand better

  • SQLSTATE[22P02]: Invalid text representation: 7 ERROR: invalid input syntax for integer: "50.00"

Show 11 more comments

1 answer

3


Already solved in chat, but who comes from outside here is the way:

$table->decimal('FIELD', 5, 2);

  • the "decimal" defined in the Laravel, precisely creates the field of type "Numeric" in the postgres

Browser other questions tagged

You are not signed in. Login or sign up in order to post.