0

I`m running a new installation of Laravel, with clean database and files.

I created a table named "frooth" and it has the columns id, title and created_at (id PK, varchar and datetime)

When I run "php artisan make:migration frooth" command, the created migration file is empty, only containing the up() and down() functions and nothing more (no columns)

How can I solve this, I followed the basic configuration of the framework as documented in official website, I can access and create functions in artisan as expected, only migrations its not working.

I generated the project with the command: composer create-project --prefer-dist laravel/laravel blog

create table laravel.frooth
(
    id         int auto_increment
        primary key,
    title      varchar(250) null,
    created_at datetime     null
);

The PHP class generated in database/migrations/2019_10_25_012925_frooth.php:

<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class Frooth extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        //
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        //
    }
}

Console output:

php artisan make:migration frooth
Created Migration: 2019_10_25_012925_frooth
  • Don't create your table manually. Use your migration file to make the table. After you add your columns to the migration table, save the file and run: `php artisan migrate` https://laravel.com/docs/5.8/migrations#generating-migrations – daugaard47 Oct 25 '19 at 02:21
  • When you have an existing database and want to make a new laravel project for it, you could use https://github.com/Xethron/migrations-generator to generate the needed migration files – julianstark999 Oct 25 '19 at 04:36
  • @JulianStark, unfortunately the Xethron/migrations-generator is incompatible with this version of Laravel, but I will test the others versions of Laravel package. – Filipe Souza Oct 25 '19 at 13:29
  • @echo In this case, I was considering to use Laravel Voyager in this project (which creates databases from its admin interface, and not creating every database in source code. But I will look forward to test that too. – Filipe Souza Oct 25 '19 at 13:30

1 Answers1

0

Delete that table you made manually and delete that migration file.

Run php artisan make:migration create_frooths_table

Then add your columns to the new migration file.

Something similar to this:

<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class Frooth extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('frooths', function (Blueprint $table) {

        $table->increments('id');
        $table->string('title')->nullable();
        $table->timestamps();
          }); 
        }
    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('frooths');
    }
}

Then run php artisan migrate

For the id you might need to use $table->bigIncrements('id'); if using Laravel 6

daugaard47
  • 1,726
  • 5
  • 39
  • 74