Postgres 9.4 JSONB data type has no default operator class #5170

Closed
opened 2026-01-22 15:00:27 +01:00 by admin · 2 comments
Owner

Originally created by @MattiasNilsson on GitHub (Jun 30, 2016).

When using the package doctrine/migrations (~1.0) together with doctrine/orm (~2.5) the following migrations fails. The migration itself worked nicely until I recenlty updated, and the last commit which was working were: https://github.com/doctrine/doctrine2/commit/4a38c96ec57e3c860c2e0c85cd98f09e685f398c

This is the backtrace of the error:

-> CREATE INDEX selectiontypes_data_ix ON tips_selectiontypes (data)
Migration 20160304100036_TableIndexes failed during Execution. Error An exception occurred while executing 'CREATE INDEX selectiontypes_data_ix ON tips_selectiontypes (data)':

SQLSTATE[42704]: Undefined object: 7 ERROR: data type json has no default operator class for access method "btree"
HINT: You must specify an operator class for the index or define a default operator class for the data type.

PHP Warning: strpos() expects parameter 1 to be string, array given in /vagrant/vendor/doctrine/dbal/lib/Doctrine/DBAL/Schema/AbstractAsset.php on line 70
PHP Stack trace:
PHP 1. {main}() /vagrant/cli.php:0
PHP 2. Symfony\Component\Console\Application->run() /vagrant/cli.php:88
PHP 3. Symfony\Component\Console\Application->doRun() /vagrant/vendor/symfony/console/Application.php:123
PHP 4. Symfony\Component\Console\Application->doRunCommand() /vagrant/vendor/symfony/console/Application.php:192
PHP 5. Symfony\Component\Console\Command\Command->run() /vagrant/vendor/symfony/console/Application.php:844
PHP 6. Doctrine\DBAL\Migrations\Tools\Console\Command\MigrateCommand->execute() /vagrant/vendor/symfony/console/Command/Command.php:259
PHP 7. Doctrine\DBAL\Migrations\Migration->migrate() /vagrant/vendor/doctrine/migrations/lib/Doctrine/DBAL/Migrations/Tools/Console/Command/MigrateCommand.php:143
PHP 8. Doctrine\DBAL\Migrations\Version->execute() /vagrant/vendor/doctrine/migrations/lib/Doctrine/DBAL/Migrations/Migration.php:176
PHP 9. BetterCollective\Migrations\Version20160119144038->up() /vagrant/vendor/doctrine/migrations/lib/Doctrine/DBAL/Migrations/Version.php:289
PHP 10. Doctrine\DBAL\Schema\Table->addForeignKeyConstraint() /vagrant/src/BetterCollective/Migrations/Version20160119144038.php:85
PHP 11. Doctrine\DBAL\Schema\Table->addNamedForeignKeyConstraint() /vagrant/vendor/doctrine/dbal/lib/Doctrine/DBAL/Schema/Table.php:393
PHP 12. Doctrine\DBAL\Schema\ForeignKeyConstraint->__construct() /vagrant/vendor/doctrine/dbal/lib/Doctrine/DBAL/Schema/Table.php:448
PHP 13. Doctrine\DBAL\Schema\AbstractAsset->_setName() /vagrant/vendor/doctrine/dbal/lib/Doctrine/DBAL/Schema/ForeignKeyConstraint.php:80
PHP 14. strpos() /vagrant/vendor/doctrine/dbal/lib/Doctrine/DBAL/Schema/AbstractAsset.php:70
PHP Warning: explode() expects parameter 2 to be string, array given in /vagrant/vendor/doctrine/dbal/lib/Doctrine/DBAL/Schema/AbstractAsset.php on line 71
PHP Stack trace:
PHP 1. {main}() /vagrant/cli.php:0
PHP 2. Symfony\Component\Console\Application->run() /vagrant/cli.php:88
PHP 3. Symfony\Component\Console\Application->doRun() /vagrant/vendor/symfony/console/Application.php:123
PHP 4. Symfony\Component\Console\Application->doRunCommand() /vagrant/vendor/symfony/console/Application.php:192
PHP 5. Symfony\Component\Console\Command\Command->run() /vagrant/vendor/symfony/console/Application.php:844
PHP 6. Doctrine\DBAL\Migrations\Tools\Console\Command\MigrateCommand->execute() /vagrant/vendor/symfony/console/Command/Command.php:259
PHP 7. Doctrine\DBAL\Migrations\Migration->migrate() /vagrant/vendor/doctrine/migrations/lib/Doctrine/DBAL/Migrations/Tools/Console/Command/MigrateCommand.php:143
PHP 8. Doctrine\DBAL\Migrations\Version->execute() /vagrant/vendor/doctrine/migrations/lib/Doctrine/DBAL/Migrations/Migration.php:176
PHP 9. BetterCollective\Migrations\Version20160119144038->up() /vagrant/vendor/doctrine/migrations/lib/Doctrine/DBAL/Migrations/Version.php:289
PHP 10. Doctrine\DBAL\Schema\Table->addForeignKeyConstraint() /vagrant/src/BetterCollective/Migrations/Version20160119144038.php:85
PHP 11. Doctrine\DBAL\Schema\Table->addNamedForeignKeyConstraint() /vagrant/vendor/doctrine/dbal/lib/Doctrine/DBAL/Schema/Table.php:393
PHP 12. Doctrine\DBAL\Schema\ForeignKeyConstraint->__construct() /vagrant/vendor/doctrine/dbal/lib/Doctrine/DBAL/Schema/Table.php:448
PHP 13. Doctrine\DBAL\Schema\AbstractAsset->_setName() /vagrant/vendor/doctrine/dbal/lib/Doctrine/DBAL/Schema/ForeignKeyConstraint.php:80
PHP 14. explode() /vagrant/vendor/doctrine/dbal/lib/Doctrine/DBAL/Schema/AbstractAsset.php:71

[Doctrine\DBAL\Exception\DriverException]
An exception occurred while executing 'CREATE INDEX selectiontypes_data_ix ON tips_selectiontypes (data)':
SQLSTATE[42704]: Undefined object: 7 ERROR: data type json has no default operator class for access method "btree"
HINT: You must specify an operator class for the index or define a default operator class for the data type.

[Doctrine\DBAL\Driver\PDOException]
SQLSTATE[42704]: Undefined object: 7 ERROR: data type json has no default operator class for access method "btree"
HINT: You must specify an operator class for the index or define a default operator class for the data type.

[PDOException]
SQLSTATE[42704]: Undefined object: 7 ERROR: data type json has no default operator class for access method "btree"
HINT: You must specify an operator class for the index or define a default operator class for the data type.

So what it fails on is that in the class Doctrine\DBAL\Schema\AbstractAsset and the following if (strpos($name, ".") !== false) which assumed that the $name variable is a string.

The command which fires this are the following:

$table = $schema->getTable('tips_selectiontypes');
$table->addIndex(['data'], 'selectiontypes_data_ix');

Any ideas?

Originally created by @MattiasNilsson on GitHub (Jun 30, 2016). When using the package doctrine/migrations (~1.0) together with doctrine/orm (~2.5) the following migrations fails. The migration itself worked nicely until I recenlty updated, and the last commit which was working were: [https://github.com/doctrine/doctrine2/commit/4a38c96ec57e3c860c2e0c85cd98f09e685f398c](https://github.com/doctrine/doctrine2/commit/4a38c96ec57e3c860c2e0c85cd98f09e685f398c) This is the backtrace of the error: > -> CREATE INDEX selectiontypes_data_ix ON tips_selectiontypes (data) > Migration 20160304100036_TableIndexes failed during Execution. Error An exception occurred while executing 'CREATE INDEX selectiontypes_data_ix ON tips_selectiontypes (data)': > > SQLSTATE[42704]: Undefined object: 7 ERROR: data type json has no default operator class for access method "btree" > HINT: You must specify an operator class for the index or define a default operator class for the data type. > > PHP Warning: strpos() expects parameter 1 to be string, array given in /vagrant/vendor/doctrine/dbal/lib/Doctrine/DBAL/Schema/AbstractAsset.php on line 70 > PHP Stack trace: > PHP 1. {main}() /vagrant/cli.php:0 > PHP 2. Symfony\Component\Console\Application->run() /vagrant/cli.php:88 > PHP 3. Symfony\Component\Console\Application->doRun() /vagrant/vendor/symfony/console/Application.php:123 > PHP 4. Symfony\Component\Console\Application->doRunCommand() /vagrant/vendor/symfony/console/Application.php:192 > PHP 5. Symfony\Component\Console\Command\Command->run() /vagrant/vendor/symfony/console/Application.php:844 > PHP 6. Doctrine\DBAL\Migrations\Tools\Console\Command\MigrateCommand->execute() /vagrant/vendor/symfony/console/Command/Command.php:259 > PHP 7. Doctrine\DBAL\Migrations\Migration->migrate() /vagrant/vendor/doctrine/migrations/lib/Doctrine/DBAL/Migrations/Tools/Console/Command/MigrateCommand.php:143 > PHP 8. Doctrine\DBAL\Migrations\Version->execute() /vagrant/vendor/doctrine/migrations/lib/Doctrine/DBAL/Migrations/Migration.php:176 > PHP 9. BetterCollective\Migrations\Version20160119144038->up() /vagrant/vendor/doctrine/migrations/lib/Doctrine/DBAL/Migrations/Version.php:289 > PHP 10. Doctrine\DBAL\Schema\Table->addForeignKeyConstraint() /vagrant/src/BetterCollective/Migrations/Version20160119144038.php:85 > PHP 11. Doctrine\DBAL\Schema\Table->addNamedForeignKeyConstraint() /vagrant/vendor/doctrine/dbal/lib/Doctrine/DBAL/Schema/Table.php:393 > PHP 12. Doctrine\DBAL\Schema\ForeignKeyConstraint->__construct() /vagrant/vendor/doctrine/dbal/lib/Doctrine/DBAL/Schema/Table.php:448 > PHP 13. Doctrine\DBAL\Schema\AbstractAsset->_setName() /vagrant/vendor/doctrine/dbal/lib/Doctrine/DBAL/Schema/ForeignKeyConstraint.php:80 > PHP 14. strpos() /vagrant/vendor/doctrine/dbal/lib/Doctrine/DBAL/Schema/AbstractAsset.php:70 > PHP Warning: explode() expects parameter 2 to be string, array given in /vagrant/vendor/doctrine/dbal/lib/Doctrine/DBAL/Schema/AbstractAsset.php on line 71 > PHP Stack trace: > PHP 1. {main}() /vagrant/cli.php:0 > PHP 2. Symfony\Component\Console\Application->run() /vagrant/cli.php:88 > PHP 3. Symfony\Component\Console\Application->doRun() /vagrant/vendor/symfony/console/Application.php:123 > PHP 4. Symfony\Component\Console\Application->doRunCommand() /vagrant/vendor/symfony/console/Application.php:192 > PHP 5. Symfony\Component\Console\Command\Command->run() /vagrant/vendor/symfony/console/Application.php:844 > PHP 6. Doctrine\DBAL\Migrations\Tools\Console\Command\MigrateCommand->execute() /vagrant/vendor/symfony/console/Command/Command.php:259 > PHP 7. Doctrine\DBAL\Migrations\Migration->migrate() /vagrant/vendor/doctrine/migrations/lib/Doctrine/DBAL/Migrations/Tools/Console/Command/MigrateCommand.php:143 > PHP 8. Doctrine\DBAL\Migrations\Version->execute() /vagrant/vendor/doctrine/migrations/lib/Doctrine/DBAL/Migrations/Migration.php:176 > PHP 9. BetterCollective\Migrations\Version20160119144038->up() /vagrant/vendor/doctrine/migrations/lib/Doctrine/DBAL/Migrations/Version.php:289 > PHP 10. Doctrine\DBAL\Schema\Table->addForeignKeyConstraint() /vagrant/src/BetterCollective/Migrations/Version20160119144038.php:85 > PHP 11. Doctrine\DBAL\Schema\Table->addNamedForeignKeyConstraint() /vagrant/vendor/doctrine/dbal/lib/Doctrine/DBAL/Schema/Table.php:393 > PHP 12. Doctrine\DBAL\Schema\ForeignKeyConstraint->__construct() /vagrant/vendor/doctrine/dbal/lib/Doctrine/DBAL/Schema/Table.php:448 > PHP 13. Doctrine\DBAL\Schema\AbstractAsset->_setName() /vagrant/vendor/doctrine/dbal/lib/Doctrine/DBAL/Schema/ForeignKeyConstraint.php:80 > PHP 14. explode() /vagrant/vendor/doctrine/dbal/lib/Doctrine/DBAL/Schema/AbstractAsset.php:71 > > [Doctrine\DBAL\Exception\DriverException] > An exception occurred while executing 'CREATE INDEX selectiontypes_data_ix ON tips_selectiontypes (data)': > SQLSTATE[42704]: Undefined object: 7 ERROR: data type json has no default operator class for access method "btree" > HINT: You must specify an operator class for the index or define a default operator class for the data type. > > [Doctrine\DBAL\Driver\PDOException] > SQLSTATE[42704]: Undefined object: 7 ERROR: data type json has no default operator class for access method "btree" > HINT: You must specify an operator class for the index or define a default operator class for the data type. > > [PDOException] > SQLSTATE[42704]: Undefined object: 7 ERROR: data type json has no default operator class for access method "btree" > HINT: You must specify an operator class for the index or define a default operator class for the data type. So what it fails on is that in the class **Doctrine\DBAL\Schema\AbstractAsset** and the following **if (strpos($name, ".") !== false)** which assumed that the $name variable is a string. The command which fires this are the following: $table = $schema->getTable('tips_selectiontypes'); $table->addIndex(['data'], 'selectiontypes_data_ix'); Any ideas?
admin closed this issue 2026-01-22 15:00:27 +01:00
Author
Owner

@stof commented on GitHub (Jul 13, 2016):

There is no code of the ORM involved here. You should open an issue on DBAL

@stof commented on GitHub (Jul 13, 2016): There is no code of the ORM involved here. You should open an issue on DBAL
Author
Owner

@stof commented on GitHub (Jul 13, 2016):

and btw, the code triggering this error is not $table->addIndex(['data'], 'selectiontypes_data_ix');. The stack traces is talking about Doctrine\DBAL\Schema\Table->addForeignKeyConstraint() /vagrant/src/BetterCollective/Migrations/Version20160119144038.php:85

@stof commented on GitHub (Jul 13, 2016): and btw, the code triggering this error is not `$table->addIndex(['data'], 'selectiontypes_data_ix');`. The stack traces is talking about `Doctrine\DBAL\Schema\Table->addForeignKeyConstraint() /vagrant/src/BetterCollective/Migrations/Version20160119144038.php:85`
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#5170