While working on a recent Statamic 3 project, I had the requirement to switch to the database eloquent driver to store Statamic users. The Storing Users in a Database knowledge base article was great to get the configuration changes done, and the base database tables created. However, after doing some testing I noticed that the project was triggering the following errors:
-
SQLSTATE[42S02]: Base table or view not found: 1146 Table 'database.password_activations' doesn't exist at
-
SQLSTATE[42S02]: Base table or view not found: 1146 Table 'database.password_resets' doesn't exist at
If you are also receiving these errors after migrating your Statamic 3 users to the database, you can follow the remaining steps to get things up and running smoothly again.
Creating the Password Activations Table
From the root of your Statamic 3 project, run the following Artisan command:
php artisan make:migration create_password_activations_table
Once this has completed, locate a new file that ends with _create_password_activations_table.php
within your projects database/migrations/
folder and set the contents to:
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class CreatePasswordActivationsTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('password_activations', function (Blueprint $table) {
$table->string('email')->index();
$table->string('token')->index();
$table->timestamp('created_at');
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::drop('password_activations');
}
}
Creating the Password Resets Table
We will perform steps similar to the password_activations
table to create our password_resets
table. From the root of your Statamic 3 project, run the following Artisan command:
php artisan make:migration create_password_resets_table
Once this has completed, locate a new file that ends with _create_password_resets_table.php
within your projects database/migrations/
folder and set the contents to:
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class CreatePasswordResetsTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('password_resets', function (Blueprint $table) {
$table->string('email')->index();
$table->string('token')->index();
$table->timestamp('created_at');
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::drop('password_resets');
}
}
Running the Migrations
Once the previous two steps have been completed, run the following Artisan command to generate your new database tables:
php artisan migrate
Conclusion
In this article, we looked at a solution to a common problem when using databases to store Statamic 3 users. The solution was to simply create the two required tables that Statamic is looking for when sending new account activation emails, or password reset emails.
If this article saved you some time, consider sharing it with your friends or colleagues!
∎