Descripción
Cuando trabajas con Symfony y Postgree, es posible que al intentar cambiar el tipo de valor para una tabla o para una columna, te encuentres con este error, que no te permitirá realizar la actualización al ejecutar el comando doctrine:migrations:migrate.
SQLSTATE[42804]: Datatype mismatch: 7 ERROR: column "xxx" cannot be cast automatically to type boolean HINT: You might need to specify "USING xxx::boolean".
Instrucciones
Para solucionar este fallo sigue los siguientes pasos:
- Asegúrate de haber generado la actualización para tu archivo dentro de la carpeta migrations. Deberías tener una archivo con un nombre parecido a este
Version20220727100245.php
- Abre el archivo con tu editor, y busca la columna relacionada con el cambio de tipo que haz intentado realizar.
- Añade el texto sugerido por el mensaje, al final de la línea donde declaras el tipo de valor para tu columna o tabla. Ej.:
$this->addSql('ALTER TABLE setting ALTER insurance TYPE BOOLEAN USING insurance::boolean'); - Vuelve a ejecutar el comando para generar tus tablas en la base de datos
Código
**
* Auto-generated Migration: Please modify to your needs!
*/
final class Version20220727100245 extends AbstractMigration
{
public function getDescription(): string
{
return '';
}
public function up(Schema $schema): void
{
// this up() migration is auto-generated, please modify it to your needs
$this->addSql('ALTER TABLE setting ALTER insurance TYPE BOOLEAN USING insurance::boolean');
$this->addSql('ALTER TABLE setting ALTER insurance DROP DEFAULT');
}
public function down(Schema $schema): void
{
// this down() migration is auto-generated, please modify it to your needs
$this->addSql('CREATE SCHEMA public');
$this->addSql('ALTER TABLE setting ALTER insurance TYPE BOOLEAN USING insurance::boolean');
$this->addSql('ALTER TABLE setting ALTER insurance DROP DEFAULT');
}
}