Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug: Database Seeder not running in Modules Exception Error Looks like the path is wrong! #9381

Closed
InsiteFX opened this issue Jan 8, 2025 · 12 comments

Comments

@InsiteFX
Copy link
Contributor

InsiteFX commented Jan 8, 2025

PHP Version

8.3

CodeIgniter4 Version

4.5.6

CodeIgniter4 Installation Method

Manual (zip or tar.gz)

Which operating systems have you tested for this bug?

Windows

Which server did you use?

apache

Database

MySQL 8.0.30

What happened?

Looks like the path is wrong using / and \ slashes in the url

php spark db:seed BlogSeeder


PS C:\laragon\www\ci4multi> php spark db:seed BlogSeeder

CodeIgniter v4.5.6 Command Line Tool - Server Time: 2025-01-08 01:23:14 UTC-05:00

[InvalidArgumentException]
The specified seeder is not a valid file: C:\laragon\www\ci4multi\app\Database/Seeds/BlogSeeder.php
at SYSTEMPATH\Database\Seeder.php:132

Backtrace:
1 SYSTEMPATH\Commands\Database\Seed.php:79
CodeIgniter\Database\Seeder()->call('BlogSeeder')

2 SYSTEMPATH\CLI\Commands.php:70
CodeIgniter\Commands\Database\Seed()->run([])

3 SYSTEMPATH\CLI\Console.php:48
CodeIgniter\CLI\Commands()->run('db:seed', [...])

4 SYSTEMPATH\Boot.php:360
CodeIgniter\CLI\Console()->run()

5 SYSTEMPATH\Boot.php:104
CodeIgniter\Boot::runCommand(Object(CodeIgniter\CLI\Console))

6 ROOTPATH\spark:84
CodeIgniter\Boot::bootSpark(Object(Config\Paths))

PS C:\laragon\www\ci4multi>

Steps to Reproduce

Create a new Module Seeder file.

php spark make:seeder BlogSeeder --namespace InsiteFX\Blog

Expected Output

Create a module seeder file.

php spark make:seeder BlogSeeder --namespace InsiteFX\Blog

Anything else?

No response

@InsiteFX InsiteFX added the bug Verified issues on the current code behavior or pull requests that will fix them label Jan 8, 2025
@michalsn
Copy link
Member

michalsn commented Jan 8, 2025

I see that you created a seeder in a specific namespace and then tried to run the command:

php spark db:seed BlogSeeder

which will search for the seeder only in the App namespace. If you want to run the seeder from the namespace you have to run the command:

php spark db:seed InsiteFX\Blog\Database\Seeds\BlogSeeder

@michalsn michalsn removed the bug Verified issues on the current code behavior or pull requests that will fix them label Jan 8, 2025
@neznaika0
Copy link
Contributor

I agree. I also got an error, but the FQCN works.

@michalsn
Copy link
Member

michalsn commented Jan 8, 2025

Seeder will not search in all namespaces for the file - this is by design. This could potentially cause problems when multiple seeder files have the same name.

@InsiteFX
Copy link
Contributor Author

InsiteFX commented Jan 8, 2025

michalsn,

I understand what you are saying, but why do the Migrations work in the namespace but the Seeder does not?
The Migrations are in the same namespace and folder.

I think that this is confusing the users. I answered 2 questions that were similar.

Shouldn't the Seeder work just like the Migrations?

Thank you

@kenjis
Copy link
Member

kenjis commented Jan 8, 2025

Migrations runs all new migration files, but seeder runs only a specified seed file.
They are different.

@michalsn
Copy link
Member

michalsn commented Jan 8, 2025

I understand what you are saying, but why do the Migrations work in the namespace but the Seeder does not?

@InsiteFX What do you mean? Calling php spark migrate will only run migrations from the App namespace. You need to use additional parameters to run all migrations or from a specific namespace.

Indeed, Seeder does not support additional parameters, but if you think they should - send a PR. Although I think allowing the calls like:

php spark db:seed -n InsiteFX\Blog
// or
php spark db:seed -all

may cause a lot of problems instead of helping users. As @kenjis mentioned, Seeders are not Migrations and they should be executed with caution because we have no history of which seeders have been called before.

@neznaika0
Copy link
Contributor

Yes. If migrations can be skipped, then Seeder will upload all its data again.
@InsiteFX What do you expect if there is app/Database/Seeds/BlogSeeder.php and InsiteFX/Database/Seeds/BlogSeeder.php? You will probably get a data conflict.

@InsiteFX
Copy link
Contributor Author

InsiteFX commented Jan 8, 2025

Ok, here is a new one, I ran migrations for Shield and the Blog all tables created.

I have tried the Seeder from InsiteFX\Blog and from the App folder and this is the error

Says it cannot find the article table but yet it is there in phpMyAdmin

Database is ci4_multi all Shield and Blog tables are there!

ERROR:

PS C:\laragon\www\ci4multi> php spark db:seed BlogSeeder

CodeIgniter v4.5.6 Command Line Tool - Server Time: 2025-01-08 07:21:58 UTC-05:00

[CodeIgniter\Database\Exceptions\DatabaseException]
Table 'ci4_multi.article' doesn't exist
at SYSTEMPATH\Database\BaseConnection.php:688

Caused by:
[CodeIgniter\Database\Exceptions\DatabaseException]
Table 'ci4_multi.article' doesn't exist
at SYSTEMPATH\Database\MySQLi\Connection.php:317

Caused by:
[mysqli_sql_exception]
Table 'ci4_multi.article' doesn't exist
at SYSTEMPATH\Database\MySQLi\Connection.php:312

Backtrace:
1 SYSTEMPATH\Database\MySQLi\Connection.php:312
mysqli()->query('INSERT INTO article (slug, lang, image, title, text, created_at, updated_at) VALUES ('article-1', 'ar', '', 'المقال باللغة العربية 1', 'المقال باللغة العربية . Lorem ipsum dolor sit amet, consectetur adipiscing eli
t. Phasellus nisi eros, ultrices vitae arcu fringilla, \nsollicitudin tempus lacus. Curabitur suscipit ex eu nisi volutpat, quis pharetra neque dictum. Sed commodo est blandit facilisis vehicula. \nUt justo mauris, ultricies eu massa ac, dignissim porttitor lig
ula. Quisque nec magna ante. Nullam accumsan nunc sed accumsan ornare. \nDonec orci mi, lobortis sed purus quis, egestas viverra justo. Cras pulvinar, mauris ut efficitur venenatis, urna justo suscipit tortor, \nnec sodales lacus quam sed dui. Sed auctor, augue
vel scelerisque molestie, ligula odio consequat ipsum, \nvel facilisis sapien velit non risus. Cras at molestie mauris. Nam a euismod purus. Cras vitae commodo orci, \nvel tempus tortor. Ut sodales, est ac volutpat congue, dui tortor luctus elit, sit amet accu
msan lectus diam a tortor. \nAenean convallis, elit vel scelerisque accumsan, enim nisi volutpat lacus, in interdum nulla elit nec nunc. \nNullam eleifend elit cursus mauris elementum porta.\n\nNulla et dui at metus pretium accumsan sed et ligula. Integer sod
ales cursus elit in commodo. Suspendisse ultrices diam elit, \nsit amet fermentum dui vulputate sit amet. Aenean a eros nec arcu tempus consectetur id cursus quam. Cras quis arcu pellentesque, \nfringilla nisl vitae, accumsan elit. Praesent nec semper velit, a
posuere diam. Quisque in arcu eros. Vivamus venenatis purus risus, \nut vehicula turpis ullamcorper nec. Morbi purus leo, lobortis sollicitudin mi sit amet, blandit aliquet orci. \nDonec tincidunt consequat felis vitae bibendum. Ut porttitor ante eget dui volut
pat venenatis. Mauris eget euismod neque, \ndapibus blandit eros. Cras condimentum metus ac mi tempor, in commodo orci vestibulum. Aliquam a ultricies leo. \nInteger quis auctor ligula. Nulla sed congue justo.', '2025-01-08 07:21:58', '2025-01-08 07:21:58')', 0)

2 SYSTEMPATH\Database\BaseConnection.php:734
CodeIgniter\Database\MySQLi\Connection()->execute('INSERT INTO article (slug, lang, image, title, text, created_at, updated_at) VALUES ('article-1', 'ar', '', 'المقال باللغة العربية 1', 'المقال باللغة العربية . Lorem ipsum dolor si
t amet, consectetur adipiscing elit. Phasellus nisi eros, ultrices vitae arcu fringilla, \nsollicitudin tempus lacus. Curabitur suscipit ex eu nisi volutpat, quis pharetra neque dictum. Sed commodo est blandit facilisis vehicula. \nUt justo mauris, ultricies eu
massa ac, dignissim porttitor ligula. Quisque nec magna ante. Nullam accumsan nunc sed accumsan ornare. \nDonec orci mi, lobortis sed purus quis, egestas viverra justo. Cras pulvinar, mauris ut efficitur venenatis, urna justo suscipit tortor, \nnec sodales lac
us quam sed dui. Sed auctor, augue vel scelerisque molestie, ligula odio consequat ipsum, \nvel facilisis sapien velit non risus. Cras at molestie mauris. Nam a euismod purus. Cras vitae commodo orci, \nvel tempus tortor. Ut sodales, est ac volutpat congue, dui
tortor luctus elit, sit amet accumsan lectus diam a tortor. \nAenean convallis, elit vel scelerisque accumsan, enim nisi volutpat lacus, in interdum nulla elit nec nunc. \nNullam eleifend elit cursus mauris elementum porta.\n\nNulla et dui at metus pretium a
ccumsan sed et ligula. Integer sodales cursus elit in commodo. Suspendisse ultrices diam elit, \nsit amet fermentum dui vulputate sit amet. Aenean a eros nec arcu tempus consectetur id cursus quam. Cras quis arcu pellentesque, \nfringilla nisl vitae, accumsan e
lit. Praesent nec semper velit, a posuere diam. Quisque in arcu eros. Vivamus venenatis purus risus, \nut vehicula turpis ullamcorper nec. Morbi purus leo, lobortis sollicitudin mi sit amet, blandit aliquet orci. \nDonec tincidunt consequat felis vitae bibendum
. Ut porttitor ante eget dui volutpat venenatis. Mauris eget euismod neque, \ndapibus blandit eros. Cras condimentum metus ac mi tempor, in commodo orci vestibulum. Aliquam a ultricies leo. \nInteger quis auctor ligula. Nulla sed congue justo.', '2025-01-08 07:21:58', '2025-01-08 07:21:58')')

3 SYSTEMPATH\Database\BaseConnection.php:648
CodeIgniter\Database\BaseConnection()->simpleQuery('INSERT INTO article (slug, lang, image, title, text, created_at, updated_at) VALUES ('article-1', 'ar', '', 'المقال باللغة العربية 1', 'المقال باللغة العربية . Lorem ipsum dolor s
it amet, consectetur adipiscing elit. Phasellus nisi eros, ultrices vitae arcu fringilla, \nsollicitudin tempus lacus. Curabitur suscipit ex eu nisi volutpat, quis pharetra neque dictum. Sed commodo est blandit facilisis vehicula. \nUt justo mauris, ultricies e
u massa ac, dignissim porttitor ligula. Quisque nec magna ante. Nullam accumsan nunc sed accumsan ornare. \nDonec orci mi, lobortis sed purus quis, egestas viverra justo. Cras pulvinar, mauris ut efficitur venenatis, urna justo suscipit tortor, \nnec sodales la
cus quam sed dui. Sed auctor, augue vel scelerisque molestie, ligula odio consequat ipsum, \nvel facilisis sapien velit non risus. Cras at molestie mauris. Nam a euismod purus. Cras vitae commodo orci, \nvel tempus tortor. Ut sodales, est ac volutpat congue, du
i tortor luctus elit, sit amet accumsan lectus diam a tortor. \nAenean convallis, elit vel scelerisque accumsan, enim nisi volutpat lacus, in interdum nulla elit nec nunc. \nNullam eleifend elit cursus mauris elementum porta.\n\nNulla et dui at metus pretium
accumsan sed et ligula. Integer sodales cursus elit in commodo. Suspendisse ultrices diam elit, \nsit amet fermentum dui vulputate sit amet. Aenean a eros nec arcu tempus consectetur id cursus quam. Cras quis arcu pellentesque, \nfringilla nisl vitae, accumsan
elit. Praesent nec semper velit, a posuere diam. Quisque in arcu eros. Vivamus venenatis purus risus, \nut vehicula turpis ullamcorper nec. Morbi purus leo, lobortis sollicitudin mi sit amet, blandit aliquet orci. \nDonec tincidunt consequat felis vitae bibendu
m. Ut porttitor ante eget dui volutpat venenatis. Mauris eget euismod neque, \ndapibus blandit eros. Cras condimentum metus ac mi tempor, in commodo orci vestibulum. Aliquam a ultricies leo. \nInteger quis auctor ligula. Nulla sed congue justo.', '2025-01-08 07:21:58', '2025-01-08 07:21:58')')

4 SYSTEMPATH\Database\BaseBuilder.php:2340
CodeIgniter\Database\BaseConnection()->query('INSERT INTO article (slug, lang, image, title, text, created_at, updated_at) VALUES (:slug:, :lang:, :image:, :title:, :text:, :created_at:, :updated_at:)', [...], false)

5 APPPATH\Database\Seeds\BlogSeeder.php:47
CodeIgniter\Database\BaseBuilder()->insert([...])

6 SYSTEMPATH\Database\Seeder.php:147
App\Database\Seeds\BlogSeeder()->run()

7 SYSTEMPATH\Commands\Database\Seed.php:79
CodeIgniter\Database\Seeder()->call('App\Database\Seeds\BlogSeeder')

8 SYSTEMPATH\CLI\Commands.php:70
CodeIgniter\Commands\Database\Seed()->run([])

9 SYSTEMPATH\CLI\Console.php:48
CodeIgniter\CLI\Commands()->run('db:seed', [...])

10 SYSTEMPATH\Boot.php:360
CodeIgniter\CLI\Console()->run()

11 SYSTEMPATH\Boot.php:104
CodeIgniter\Boot::runCommand(Object(CodeIgniter\CLI\Console))

12 ROOTPATH\spark:84
CodeIgniter\Boot::bootSpark(Object(Config\Paths))

PS C:\laragon\www\ci4multi>

Same ERROR from both Seeders

php spark db:seed InsiteFX\Blog\Database\Seeds\BlogSeeder

php spark db:seed BlogSeeder

This is a Windows 11 Pro System

@neznaika0
Copy link
Contributor

There may be an error due to Win 11. Check the paths in the database and in Seeder. Especially the slashes

@InsiteFX
Copy link
Contributor Author

InsiteFX commented Jan 8, 2025

The seeder files were deleted from the folder that was not being used.

There were no two seeders with the same name, I deleted them from the folder not being used.

This use to work because I seeded the blog before using IncludeBeers seeder a few months ago,
This is the same file that use to work.

@michalsn
Copy link
Member

michalsn commented Jan 8, 2025

Please provide some more code - your migration and seeder, so we can try to reproduce the error.

@InsiteFX
Copy link
Contributor Author

InsiteFX commented Jan 9, 2025

I apologize to the CodeIgniter Development Team.

I had like 25 records in the BlogSeeder file and one of them was spelled wrong missing an s on the
end of the table name articles.

All is working now from App and Module Blog, so I' am closing the issue

Just another stupid mistake.

Thank you

@InsiteFX InsiteFX closed this as completed Jan 9, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants