Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

jwavess's avatar

How would one type out $blah->save(); in php artisan if one is using MySQL?

How would one type out $blah->save(); in php artisan if one is using MySQL? Everything was going smooth up until I typed $testone->save();

I got the following error

Illuminate\Database\QueryException with message 'SQLSTATE[42S02]: Base table or view not found: 1146 Table 'homestead.testones' doesn't exist (SQL: insert into testones (row, rowtwo, rowthree, rowfour, updated_at, created_at) values (My first row, My second row, My third row, My fourth row, 2016-01-08 18:24:53, 2016-01-08 18:24:53))'

Would it be MySQL Dump or something? Or some sort of insert quarry statement.

Seth

0 likes
7 replies
jhoff's avatar

Have you created a database migration for your testone model? Have you run php artisan migrate? Your error message is indicating that there isn't a corresponding table for your model.

joedawson's avatar

Are you doing this on your machine or when you've SSH'd into the Homestead box?

jwavess's avatar

@JoeDawson when Ive ssh'ed. So the steps should be the following.

vm (vagrant shh) cd Code/projectone; php artisan make:model testone php artisan migrate php artisan tinker $testone = new App\testone; $testone->rowone = "valueone"; $testone->rowtwo = "valuetwo"; $testone->rowthree = "valuethree"; $testone-save();

? is that right. Or am I suppose to

vm (vagrant shh) php artisan migrate

in a new terminal tab after I did the

$testone = new App\testone; $testone->rowone = "valueone"; $testone->rowtwo = "value two"; $testone->rowthree = "value three";

joedawson's avatar

The first thing you want to do, is check your database - you're seeing an error that your table testones does not exist in your homestead database. I really hope I'm not coming across rude here, but the error is quite clear what's wrong - the errors are made to be as clear as possible to help you debug :)

If your table testones does not exist, then you need to run php artisan migrate as @jhoff suggested.

You'll get one of two messages, either "Nothing to migrate." - this means all of your migrations in your /database/migrations folder have been migrated to the database you specified.

Or, you'll receive a message saying that migration was successful. What do you get here?

1 like
jwavess's avatar

No worries @JoeDawson , and I was receiving the error "Nothing to migrate". So I checked to see if it was in there with these steps

Cd Homestead; vm

mysql -u homestead -p .. use homestead; show tables;

And test one is indeed present.

Also when I am creating a table with php artisan, is this written out correctly?

php artisan make:migration testone --create="testone"

Or would it be

php artisan make:migration create_testone_table --create="testone"

michaeldyrynda's avatar

Did you edit the migration before you ran php artisan migrate?

If not, that table will have only the default columns: id, created_at, and updated_at. Your earlier post indicates you were trying to save values to fields rowone, rowtwo, and rowthree. The way you wrote your example above is inserting three fields (columns) in the same record (row) i.e. you need to add those three columns to your migration before you run it.

julian's avatar
//App/testone.php

protected $table = "testone";

Why?

In your Migration you call your database "testone"

php artisan make:migration testone --create="testone"

And your Model is also Called testone

php artisan make:model testone

Laravel Searches now for the Plural of "testone" so the database must be either named correctly "testones" or you need to pass the $table name to your model.

1 like

Please or to participate in this conversation.