Welcome Guest, Not a member yet? Register   Sign In
[SOLVED] Migrations in modules?
#1

(This post was last modified: 04-28-2019, 03:43 PM by MeltedRolo.)

Hi guys.

Just trying to get a module migration working and seem to be having a bit of bother.

I have done exactly what is described in the following article ...

Modules_in_CodeIgniter_4

Now my question is, in the migration file, what namespace am I supposed to be using?

And, they are supposed to just work right? no more configuring?

Thanks
Reply
#2

It will include all migrations it finds in Database/Migrations.

So by the User Guide you need to store your migrations under your namespace/Database/Migrations
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply
#3

Hi

Thanks for the response.

My Directory layout is as follows ...

App/ ...
Standard/Auth/Database/Migrations/
System/ ...

etc

My migration file in the above migration dir is 20190427134005_add_auth_users.php

and contains the following ...

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

use 
CodeIgniter\Database\Migration;

class 
Migration_Add_auth_users extends Migration
{
 public function 
up()
 {
 
$fields = [
 
'id' => ['type' => 'INT''constraint' => 9'unsigned' => true'auto_increment' => true],
 
'title'  => ['type' => 'VARCHAR''constraint' => '100''unique' => true]
 ];

 
$this->forge->addField($fields);
 
$this->forge->addKey('id'true);
 
$this->forge->createTable('users');
 }

 
//--------------------------------------------------------------------

 
public function down()
 {
 
$this->forge->dropTable('users');
 }


I then execute the following in the terminal ...

PHP Code:
php spark migrate:latest -all 

Which is supposed to run all the migrations, but doesnt, only the ones located in the main app directory.

My autoload.php file in the main app config dir is changed as follows ...

PHP Code:
$psr4 = [
 
'Config'      => APPPATH 'Config',
 
APP_NAMESPACE => APPPATH               // For custom namespace
 
'App'         => APPPATH               // To ensure filters, etc still found,
 
'Standard'    => APPPATH '../standard'
]; 

I dunno what I'm doing wrong.
Reply
#4

(This post was last modified: 04-28-2019, 03:32 AM by InsiteFX.)

Your namespace for standard should be in the root .

PHP Code:
app
system
standard

'Standard'      => ROOTPATH 'Standard',
'Standard/Auth' => ROOTPATH 'Standard/Auth'

When you use APPPATH or ROOTPATH you do not add the forward slash either.
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply
#5

What InsiteFX said is right, and just to point out the main difference is your path is missing the “/Auth” at the end of your namespace.
Reply
#6

Ahh I see.

Didn't realise that, thanks very much.
Reply
#7

(This post was last modified: 04-28-2019, 10:47 AM by MeltedRolo.)

Hi again.

So I managed to get it do something, unfortunately it's still not working.

When I run the migrate all command I get the following ...


Code:
The migration class "Standard\Auth\Database\Migrations\Migration_add_auth_users" could not be found.
C:\xampp\www\public\ci4\system\Database\MigrationRunner.php - 274


Think it has something to do with the namespace, because its finding the file, but cant find the class inside the file.
Reply
#8

Sorted.

So my original question was ...


Quote:Now my question is, in the migration file, what namespace am I supposed to be using?


And the answer is ...


PHP Code:
<? namespace Standard\Auth\Database\Migrations 
Reply




Theme © iAndrew 2016 - Forum software by © MyBB