codeigniter4 / shield

Authentication and Authorization for CodeIgniter 4
https://shield.codeigniter.com
MIT License
366 stars 133 forks source link

[PostgreSQL] Error migrate:rollback #327

Closed caosdp-rs closed 2 years ago

caosdp-rs commented 2 years ago

Postgresql 11

PS C:\laragon\www\creditos> php spark migrate:rollback

CodeIgniter v4.2.1 Command Line Tool - Server Time: 2022-07-29 18:07:49 UTC-03:00

Revertendo todas as migrações... 0

[ErrorException]

pg_query(): Query failed: ERROR: cannot drop table users because other objects depend on it DETAIL: constraint auth_identities_user_id_foreign on table auth_identities depends on table users constraint auth_remember_tokens_user_id_foreign on table auth_remember_tokens depends on table users constraint auth_groups_users_user_id_foreign on table auth_groups_users depends on table users constraint auth_permissions_users_user_id_foreign on table auth_permissions_users depends on table users HINT: Use DROP ... CASCADE to drop the dependent objects too.

at SYSTEMPATH\Database\Postgre\Connection.php:135

Backtrace: 1 [internal function] CodeIgniter\Debug\Exceptions()->errorHandler(2, 'pg_query(): Query failed: ERROR: cannot drop table users because other objects depend on it DETAIL: constraint auth_identities_user_id_foreign on table auth_identities depends on table users constraint auth_remember_tokens_user_id_foreign on table auth_remember_tokens depends on table users constraint auth_groups_users_user_id_foreign on table auth_groups_users depends on table users constraint auth_permissions_users_user_id_foreign on table auth_permissions_users depends on table users HINT: Use DROP ... CASCADE to drop the dependent objects too.', 'C:\laragon\www\creditos\vendor\codeigniter4\framework\system\Database\Postgre\Connection.php', 135, [...])

2 SYSTEMPATH\Database\Postgre\Connection.php:135 pg_query(NULL, 'DROP TABLE IF EXISTS "users"')

3 SYSTEMPATH\Database\BaseConnection.php:695 CodeIgniter\Database\Postgre\Connection()->execute('DROP TABLE IF EXISTS "users"')

4 SYSTEMPATH\Database\BaseConnection.php:609 CodeIgniter\Database\BaseConnection()->simpleQuery('DROP TABLE IF EXISTS "users"')

5 SYSTEMPATH\Database\Forge.php:614 CodeIgniter\Database\BaseConnection()->query('DROP TABLE IF EXISTS "users"')

6 VENDORPATH\codeigniter4\shield\src\Database\Migrations\2020-12-28-223112_create_auth_tables.php:139 CodeIgniter\Database\Forge()->dropTable('users', true)

7 SYSTEMPATH\Database\MigrationRunner.php:868 CodeIgniter\Shield\Database\Migrations\CreateAuthTables()->down()

8 SYSTEMPATH\Database\MigrationRunner.php:298 CodeIgniter\Database\MigrationRunner()->migrate('down', Object(stdClass))

9 SYSTEMPATH\Commands\Database\MigrateRollback.php:92 CodeIgniter\Database\MigrationRunner()->regress(0)

10 SYSTEMPATH\CLI\Commands.php:63 CodeIgniter\Commands\Database\MigrateRollback()->run([])

11 SYSTEMPATH\CLI\CommandRunner.php:65 CodeIgniter\CLI\Commands()->run('migrate:rollback', [])

12 SYSTEMPATH\CLI\CommandRunner.php:51 CodeIgniter\CLI\CommandRunner()->index([])

13 SYSTEMPATH\CodeIgniter.php:889 CodeIgniter\CLI\CommandRunner()->_remap('index', [...])

14 SYSTEMPATH\CodeIgniter.php:466 CodeIgniter\CodeIgniter()->runController(Object(CodeIgniter\CLI\CommandRunner))

15 SYSTEMPATH\CodeIgniter.php:345 CodeIgniter\CodeIgniter()->handleRequest(null, Object(Config\Cache), false)

16 SYSTEMPATH\CLI\Console.php:48 CodeIgniter\CodeIgniter()->run()

17 ROOTPATH\spark:86 CodeIgniter\CLI\Console()->run()

caosdp-rs commented 2 years ago

change position $this->forge->dropTable('users', true); to last line

kenjis commented 2 years ago

Thank you for reporting.

It seems you are the first person who uses PostgreSQL with Shield. PRs are welcome! See https://github.com/codeigniter4/CodeIgniter4/blob/develop/contributing/README.md

kenjis commented 2 years ago

DEFERRABLE NOT DEFERRABLE

This controls whether the constraint can be deferred. A constraint that is not deferrable will be checked immediately after every command. Checking of constraints that are deferrable can be postponed until the end of the transaction (using the SET CONSTRAINTS command). NOT DEFERRABLE is the default. Currently, only UNIQUE, PRIMARY KEY, EXCLUDE, and REFERENCES (foreign key) constraints accept this clause. NOT NULL and CHECK constraints are not deferrable. Note that deferrable constraints cannot be used as conflict arbitrators in an INSERT statement that includes an ON CONFLICT DO UPDATE clause. https://www.postgresql.org/docs/14/sql-createtable.html