CodeIgniter Forums
Migration not working - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: CodeIgniter 4 (https://forum.codeigniter.com/forum-28.html)
+--- Forum: CodeIgniter 4 Support (https://forum.codeigniter.com/forum-30.html)
+--- Thread: Migration not working (/thread-70546.html)



Migration not working - ponzo - 04-25-2018

I'm following the migration documentation, but I cant get a working example.

"The migration class "App\Database\Migrations\Migration_Add_blog" could not be found."

In Database/Migrations there is the file 20121031100537_Add_blog.php

The current version is, in config/Migrations.php



Code:
$currentVersion = 20121031100537;

Within the controller I have


PHP Code:
<?php namespace App\Controllers;
use 
CodeIgniter\Controller;

class 
Migrate extends \CodeIgniter\Controller
{

        public function index()
        {
                $migrate = \Config\Services::migrations();

                try
                {
                  $migrate->current();
                
                
}
                catch (\Exception $e)
                {
                  // Do something with the error here...
                    echo "<pre>";
                    var_dump($e);
                    echo "</pre>";
                }
        }



I only added:
PHP Code:
<?php namespace App\Controllers;
use 
CodeIgniter\Controller

To make it accessible

When i switch to sequential
001_add_blog.php

I got the same error,

when i change the file to 1_add_blog.php, it gives no errors, but no table is added


Any idea?

thanks


RE: Migration not working - natanfelles - 04-25-2018

Hey @ponzo. Namespace your migration:

Code:
<?php namespace App\Database\Migrations;

The docs example are not showing it.


RE: Migration not working - ponzo - 04-25-2018

Thank you.

Adding


Code:
<?php namespace App\Database\Migrations;

To 001_add_blog.php is the sollution. Maybe this can added to the docs, from Ci3 i'm quite new to namespaces