Search

Enabling Database Users in Statamic 3

February 20, 2021 —John Koster

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:

1php 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:

1<?php
2 
3use Illuminate\Database\Migrations\Migration;
4use Illuminate\Database\Schema\Blueprint;
5use Illuminate\Support\Facades\Schema;
6 
7class CreatePasswordActivationsTable extends Migration
8{
9 
10 /**
11 * Run the migrations.
12 *
13 * @return void
14 */
15 public function up()
16 {
17 Schema::create('password_activations', function (Blueprint $table) {
18 $table->string('email')->index();
19 $table->string('token')->index();
20 $table->timestamp('created_at');
21 });
22 }
23 
24 /**
25 * Reverse the migrations.
26 *
27 * @return void
28 */
29 public function down()
30 {
31 Schema::drop('password_activations');
32 }
33 
34}

#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:

1php 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:

1<?php
2 
3use Illuminate\Database\Migrations\Migration;
4use Illuminate\Database\Schema\Blueprint;
5use Illuminate\Support\Facades\Schema;
6 
7class CreatePasswordResetsTable extends Migration
8{
9 
10 /**
11 * Run the migrations.
12 *
13 * @return void
14 */
15 public function up()
16 {
17 Schema::create('password_resets', function (Blueprint $table) {
18 $table->string('email')->index();
19 $table->string('token')->index();
20 $table->timestamp('created_at');
21 });
22 }
23 
24 /**
25 * Reverse the migrations.
26 *
27 * @return void
28 */
29 public function down()
30 {
31 Schema::drop('password_resets');
32 }
33}

#Running the Migrations

Once the previous two steps have been completed, run the following Artisan command to generate your new database tables:

1php 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.