2
votes

I added a new table in migration in file 2018_02_08_094356_create_currency_table.php..

And this is the code:

<?php

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

class CreateCurrencyTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('currency', function (Blueprint $table) {
            $table->increments('id');
            $table->decimal('usdeur', 15, 2);
            $table->decimal('usdchf', 15, 2);
            $table->timestamps();
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('currency');
    }
}

When I run php artisan migrate, there is only default laravel users (and migration) table in my DB. No currency one.

What could be the reason?

EDIT

Everything was fine with migrations. The problem was this:

[Illuminate\Database\QueryException] SQLSTATE[42000]: Syntax error or access violation: 1071 Specified key was too long; max key length is 767 bytes (SQL: alter table users add unique users_email_unique(email))

[PDOException] SQLSTATE[42000]: Syntax error or access violation: 1071 Specified key was too long; max key length is 767 bytes

Solution is to add this in AppServiceProvider.php

public function boot()
{
    Schema::defaultStringLength(191);
}

Source: https://laravel-news.com/laravel-5-4-key-too-long-error

3
If you don't have data you need to keep, run php artisan migrate:fresh first. Sounds like you have migration records in the db. This will drop all your tables so be warned.user320487

3 Answers

1
votes

You need to run composer du to register the migration class first.

Then run php artisan migrate command to execute a new migration.

1
votes

open AppServiceProvider.php write the below code:

public function boot()
{
    Schema::defaultStringLength(191);
}

The table name must be plural rollback your migration using

php artisan migrate:rollback

or

manually delete the table from your database and migration table and try the below code:

migration command:
php artisan make:migration create_currencies_table

Code:

class CreateCurrenciesTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('currencies', function (Blueprint $table) {
            $table->increments('id');
            $table->decimal('usdeur', 15, 2);
            $table->decimal('usdchf', 15, 2);
            $table->timestamps();
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('currencies');
    }
}

now run

php artisan migrate
0
votes

All the migrations record are recorded in table migrations.It is indicate that you created it before.So delete the records about currencies in table migrations and run php artisan migrate again. what's more,refresh your database and check if the table currencies has created.