Error when running php Artisan migrate

Asked

Viewed 444 times

2

I am trying to create the tables and this giving the following error:

  BadMethodCallException  : Method Illuminate\Database\Schema\Blueprint::number does not exist.
  at /var/www/html/clinicas/vendor/laravel/framework/src/Illuminate/Support/Traits/Macroable.php:99
 95|      */
 96|     public function __call($method, $parameters)
 97|     {
 98|         if (! static::hasMacro($method)) {
  >  99|             throw new BadMethodCallException(sprintf(
100|                 'Method %s::%s does not exist.', static::class, $method
101|             ));
102|         }
103
Exception trace:
1   Illuminate\Database\Schema\Blueprint::__call("number")
/var/www/html/clinicas/database/migrations/2018_06_05_225926_create_pacientes_table.php:19
2   CreatePacientesTable::{closure}(Object(Illuminate\Database\Schema\Blueprint))
  /var/www/html/clinicas/vendor/laravel/framework/src/Illuminate/Database/Schema/Builder.php:164

My Migrations: Users

public function up()
{
    Schema::create('users', function (Blueprint $table) {
        $table->increments('id');
        $table->string('name');
        $table->string('email')->unique();
        $table->string('password');
        $table->string('nivel', 5)->nullable();
        $table->rememberToken();
        $table->timestamps();
    });
}

Password

public function up()
{
    Schema::create('password_resets', function (Blueprint $table) {
        $table->string('email')->index();
        $table->string('token');
        $table->timestamp('created_at')->nullable();
    });
}

Events

public function up()
{
    Schema::create('eventos', function (Blueprint $table) {
        $table->increments('id');
        $table->string('titulo');
        $table->datetime('start');
        $table->datetime('end');
        $table->string('color', 7);
        $table->timestamps();
    });
}

Patients

public function up()
{
    Schema::create('pacientes', function (Blueprint $table) {
        $table->increments('id');
        $table->string('nome');
        $table->number('cpf');
        $table->number('rg');
        $table->string('endereco');
        $table->string('numero');
        $table->string('bairro');
        $table->string('cep');
        $table->string('cidade');
        $table->string('estado');
        $table->string('telefone');
        $table->string('celular');
        $table->string('celular_2');
        $table->string('email');
        $table->string('imagem');
        $table->timestamps();
    });
}

What could be wrong?

  • What is the line 2018_06_05_225926_create_pacientes_table.php:19?

  • 1

    $table->number(...); Does not exist, instead use integer or string. https://laravel.com/docs/5.7/migrations#Columns

  • That’s right! It was declared the number! Thank you

1 answer

1

The problem occurs in the method number();, because it does not exist, as the columns you are using is intended to CPF or RG can use string(); same, or if it is only numbers (without the points and -) you can use the integer();

Patients:

public function up()
{
    Schema::create('pacientes', function (Blueprint $table) {
        $table->increments('id');
        $table->string('nome');
        $table->string('cpf');
        $table->string('rg');
        $table->string('endereco');
        $table->string('numero');
        $table->string('bairro');
        $table->string('cep');
        $table->string('cidade');
        $table->string('estado');
        $table->string('telefone');
        $table->string('celular');
        $table->string('celular_2');
        $table->string('email');
        $table->string('imagem');
        $table->timestamps();
    });
}

You can check the methods to create the columns in the following Link

Browser other questions tagged

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