Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

PHP Laravel 4 Basics Relating Data Model relation

Cannot run final migration to create todo_items_table - any pointers?

Hi there,

I have followed the video all the way through, and made a create_todo_items_table.php model file. However, near the end when I come to run the final migration (php artisan migrate), I receive the following error message from within the command line:

[PDO Exception] SQLSTATE [42S01] Base table or view already exists - 'todo_lists' already exists

Then when I run a 'SHOW TABLES' command on the database 'odot', I cannot see the todo_items table in the list. All I see are the four tables, 'migrations', 'password_resets', 'todo_lists', 'users'.

Is Laravel attempting to create my todo_items table?

Here is the code for my model file create_todo_items_table.php:

<?php

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

class CreateTodoItmesTable extends Migration {

    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('todo_items', function(Blueprint $table)
        {
            $table->increments('id');
            $table->integer('todo_list_id');
            $table->string('content')->unique();
            $table->dateTime('completed_on')->nullable();
            $table->timestamps();
        });
    }

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

Any pointers would be very helpful!

Thanks,

Robert London, UK

4 Answers

Hello Robert,

Can you post you migration for todo_lists. Thank you

Kristian,

Thankyou.

Here is my migration for todo_lists, that i created some time ago back in August when I was commencing this tutorial:

<?php

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

class CreateTodoListsTable extends Migration {

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

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down() // if we roll back a migration, if we go backwards in our version control, what are we going to do?
    {
        Schema::drop('todo_lists');
    }

}

// After setting up what we need here, we need to go back to our terminal to run the migration
?>

Please let me know if you notice anything untoward, or if you have any other ideas!

Thanks,

Robert

If you don't have any important information inside the database run php artisan migrate:reset and then php artisan migrate

Hi Kristian,

I have completed just what you mentioned above, and the migration still does not work, and I still end up with exactly the same error as described in my first post.

For now, I think I will create the todo_list_items table manually in MySQL - rather than just sit here stuck...

Thanks,

Robert.