57

I am trying to create mysql tables in Laravel 5. I created a file in /project/database/migrations called users.php:

[...]
public function up()
{
    Schema::create('users', function(Blueprint $table)
    {
        $table->increments('id');
        $table->string('username');
        $table->string('fullname');
        $table->int('number');
        $table->string('email')->unique();
        $table->string('password', 60);
        $table->rememberToken();
        $table->timestamps();
    });
}
[...]

I then tried running these commands in the project-folder:

$ php artisan migrate
$ php artisan migrate:install
$ php artisan migrate --pretend

None of them return any output and no tables are created. The database to be populated exists.

1
  • 2
    Please use this command php artisan make:migration CreateUsersTable --create to create migration and then run php artisan migrate Commented May 26, 2015 at 0:08

5 Answers 5

112

Migration files must match the pattern *_*.php, or else they won't be found. Since users.php does not match this pattern (it has no underscore), this file will not be found by the migrator.

Ideally, you should be creating your migration files using artisan:

php artisan make:migration create_users_table

This will create the file with the appropriate name, which you can then edit to flesh out your migration. The name will also include the timestamp, to help the migrator determine the order of migrations.

You can also use the --create or --table switches to add a little bit more boilerplate to help get you started:

php artisan make:migration create_users_table --create=users

The documentation on migrations can be found here.

Sign up to request clarification or add additional context in comments.

Comments

2

in laravel 5 first we need to create migration and then run the migration

Step 1.

php artisan make:migration create_users_table --create=users

Step 2.

php artisan migrate

1 Comment

Please do not duplicate existing answers, unless you have something new to add
1

First You have to create a migration file by the Following Command!

php artisan make:migration create_users_table --create=users

Now You can add your required fields in function up

    public function up()
{
    Schema::create('users', function(Blueprint $table)
    {
        $table->increments('id');
        $table->string('username');
        $table->string('fullname');
        $table->int('number');
        $table->string('email')->unique();
        $table->string('password', 60);
        $table->rememberToken();
        $table->timestamps();
    });
}

In Last you Just have to run this command to migrate your table in database

php artisan migrate

Comments

0

Create migration and run only created migration.

php artisan make:migration create_users_table --create=users

php artisan migrate --path=/database/migrations/0000_00_00_000000_create_users_table.php

Comments

-3

In order to give a value in the table, we need to give a command:

php artisan make:migration create_users_table

and after then this command line

php artisan migrate

......

2 Comments

Please share more details, such that others can learn from your answer. The given hint about using the make:migration command has already been shared five years ago
already answered by other guys. do not copy the answers.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.