Reputation: 892
I am having trouble getting up and going with Laravel. The database (MySQL) is giving me some errors, but I am uncertain how to go about fixing them. I wrote this simple migration to create a songs table.
<?php
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class CreateSongsTable extends Migration
{
// Run the migrations.
public function up()
{
Schema::create('songs', function (Blueprint $table) {
$table->increments('id');
$table->string('title'); /* <- Here is the title column */
$table->text('lyrics')->nullable();
$table->timestamps();
});
}
// Reverse the migrations.
public function down()
{
Schema::drop('songs');
}
}
Then I migrate it and everything seems to be working fine.
$ php artisan migrate
Migrated: 2015_07_14_150540_create_songs_table
But when I try to insert something an error shows up. It says that I am missing the title column, but at far as I can see in my code above, I should have one, and I get no errors otherwise.
$ php artisan tinker
Psy Shell v0.5.1 (PHP 5.5.24 — cli) by Justin Hileman
>>> DB::table('songs')->insert([ 'title' => 'Fall',
'created_at' => new DateTime, 'updated_at' => new DateTime]);
Illuminate\Database\QueryException with message 'SQLSTATE[42S22]:
Column not found: 1054 Unknown column 'title' in 'field list'
(SQL: insert into `songs` (`title`, `created_at`, `updated_at`)
values (Fall, 2015-07-14 15:14:10, 2015-07-14 15:14:10))'
Edit: Looking at the database in phpMyAdmin, The table is there, but the title column is missing. Here is what I get:
Where am I going wrong?
Upvotes: 2
Views: 2472
Reputation: 2716
The Table hasn't been migrated into the database.
Please use
php artisan migrate:refresh
to reinstate your table
Upvotes: 4