Support the ongoing development of Laravel.io →
posted 8 years ago
Database
Last updated 6 months ago.
0

I think the actual artisan command help for this item is incorrect or not clear. The working syntax for creating a table is:

php artisan migrate:make create_links_table --table=links --create=true

The MigrateMakeCommand class passes a boolean value taken from the --create argument. The help says the table to create which is not correct. The default value for --create is false. Passing true will use the correct stub/template for how you are wanting.

Last updated 6 months ago.
0
php artisan migrate:make create_links_table --create=links

refer Creating Migrations you need to create new table, so use --create=links (links is the table name)

should create file with following content

<?php

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

class CreateLinksTable extends Migration {

	/**
	 * Run the migrations.
	 *
	 * @return void
	 */
	public function up()
	{
		Schema::create('links', function(Blueprint $table)
		{
			$table->increments('id');
			$table->timestamps();
		});
	}

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

}

Now you can include additional columns you needed, so based on your example it would be like below after changes (I assume you don't need timestamp fields so I removed it)

<?php

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

class CreateLinksTable extends Migration {

	/**
	 * Run the migrations.
	 *
	 * @return void
	 */
	public function up()
	{
		Schema::create('links', function(Blueprint $table)
		{
			$table->increments('id');
            $table->text('url');
            $table->string('hash',400);

		});
	}

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

}

then run following command in command line to migrate

$ php artisan migrate
Migrated: 2014_09_07_072738_create_links_table

If you want to rollback (remove the table from database)

$ php artisan migrate:rollback
Rolled back: 2014_09_07_072738_create_links_table
Last updated 6 months ago.
0

Sign in to participate in this thread!

LoadForge

Your banner here too?

narfed narfed Joined 5 Sep 2014

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2022 Laravel.io - All rights reserved.