Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Artisan, creating tables in database

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.

like image 976
Streetlamp Avatar asked May 25 '15 23:05

Streetlamp


People also ask

What in Laravel helps in creating tables?

The Laravel Schema facade provides database agnostic support for creating and manipulating tables across all of Laravel's supported database systems.

Which artisan command is used to migrate a database?

To create a new migration, you can run the make:migration Artisan command and that will bootstrap a new class on your Laravel application, in the database/migrations folder.

What methods are used in database migration classes?

A migration class contains two methods: up and down . The up method is used to add new tables, columns, or indexes to your database, while the down method should simply reverse the operations performed by the up method.


2 Answers

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 
like image 26
Rajesh kumar Avatar answered Oct 05 '22 16:10

Rajesh kumar


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.

like image 98
patricus Avatar answered Oct 05 '22 16:10

patricus