Run seed command in module |
I have create an Admin module, to add an Admin user into the db I created a seed file into the Admin\Database\Seeds path, below the code of the seeder
Code: namespace Admin\Database\Seeds; The issue arises when I run the php spark dbeed NameFile command...I got the following error, since it seems that the command looks for the seeder file into the main app folder. [InvalidArgumentException] The specified seeder is not a valid file: D:\project\app\Database/Seeds/AddAdminAccount I'm sure that could be an option to set spark db command to run in Admin module namespace...but I wasn't able to find it in CI documentation...am I wrong? Is it possible to run seed file in Admin module? Thanks a lot for your feedback
You can get all spark commands from your terminal using this command:
Code: php spark list For namespaces it shows here how to do it: CodeIgniter 4 Users Guide - Managing Databases - Database Seeding What did you Try? What did you Get? What did you Expect?
Joined CodeIgniter Community 2009. ( Skype: insitfx )
Thanks for feedback InsiteFX.
I knew about spark list command...in this case the level of info details in that command is useless to fix my issue, even the php spark db seed --help command doesn't provide any useful info. I knew the Managing Database Seeding page in CI web site...I followed that info ( and the Dave Hollingworth course ) to create the seed file into the module Admin folder...using the command Code: php spark make:seeder AddAdminAccount --namespace Admin Unfortunately I don't find any command to run the seed file in the Admin namespace The following command: Code: php spark db:seed AddAdminAccount return the following error Code: The specified seeder is not a valid file: D:\Aero Club Belluno\composer-aeclidb\app\Database/Seeds/AddAdminAccount.php I tried to add namespace, with Code: php spark db:seed AddAdminAccount --namespace Admin But again the same error I'm doing something wrong...I'm sure the fault is on my side...but from the documentation around here I cannot find the fix Again, thanks for taking the time to help
01-06-2025, 03:24 AM
(This post was last modified: 01-06-2025, 03:27 AM by InsiteFX. Edit Reason: add other stuff to reply )
This does not look right, look at the the slashes some are back slashes and others are forward slashes
they should all be the same not mixed. Code: D:\Aero Club Belluno\composer-aeclidb\app\Database/Seeds/AddAdminAccount.php I'll see if I can find some time later to look deeper in to this problem. Also I would stay away from using spaces in file and folder names they can cause problems. What did you Try? What did you Get? What did you Expect?
Joined CodeIgniter Community 2009. ( Skype: insitfx )
Thanks a lot for all your support InsiteFX.
Me too, I noticed the weird mixed slashes in the error message ...and you are right...better stay away from using spaces in file and folder names they can cause problem...I can live for sure with seeder into their standard app\Database\Seedes folder...I was just curious to understand the reason the seed didn't work even if we can create it into module as official Documentation says....maybe we found a bug, who knows. In any case, it would be fine if the seeder could be run in Module...it could come in handy to develop a self-contained module structure...just my 2 cents, of course Again, thanks a lot for taking the time to look into it and for all your priceless support.
One thing that is critical is that you need to have the module path in the Autoload.php file like below
for it to find the seeder in a module. PHP Code: public $psr4 = [ What did you Try? What did you Get? What did you Expect?
Joined CodeIgniter Community 2009. ( Skype: insitfx )
I Created the Migration and Seeder files using the namespace and both files where created
in InsiteFX/Blog. Code: php spark make:migration BlogTables --namespace InsiteFX/Blog I'll test this out later today and let you know if I come across any problems. What did you Try? What did you Get? What did you Expect?
Joined CodeIgniter Community 2009. ( Skype: insitfx )
Ok, I just ran it and I get the same error as you do, I have created a Bug Report on GitHub.
We just have to wait now for an answer. What did you Try? What did you Get? What did you Expect?
Joined CodeIgniter Community 2009. ( Skype: insitfx )
Ok, there was an error in my Seeder file that was causing my problems but all works now
For Seeding from the App folder: Code: php spark db:seed YourSeederName For Seeding from the Modules folder - must pass the namespace: Code: php spark db:seed Modules\YourModuleName\Database\Seeds\YourSeederName What did you Try? What did you Get? What did you Expect?
Joined CodeIgniter Community 2009. ( Skype: insitfx )
|
Welcome Guest, Not a member yet? Register Sign In |