type rails column ruby-on-rails-3 postgresql encoding rake-task

ruby-on-rails-3 - rails - rake db rollback migration



rake db: crea un error de codificación con postgresql (5)

Añadiendo

template: template0

en config / database.yml funcionó para mí :-)

Estoy importando un proyecto de rieles existente en el que estaba trabajando en mi nuevo sistema arch Linux, ya instalé todas las gemas y postgresql correctamente, pero tengo algunos problemas al ejecutar:

rake db:create

Obtuve el siguiente error

PGError: ERROR: new encoding (UTF8) is incompatible with the encoding of the template database (SQL_ASCII) HINT: Use the same encoding as in the template database, or use template0 as template. : CREATE DATABASE "System_test" ENCODING = ''unicode''

Creé manualmente la base de datos con la codificación correcta y las migraciones funcionaron bien, pero puedo ejecutar el

rake db:test:clone

comando porque intenta crear una base de datos y no creo que cree manualmente las bases de datos tampoco. Entonces, alguien sabe arreglar esto?

saludos

EDITAR: aquí está mi database.yml

development: adapter: postgresql encoding: unicode database: System_development pool: 5 username: forellana password: test: &test adapter: postgresql encoding: unicode database: System_test pool: 5 username: forellana password: cucumber: <<: *test

y aquí está la salida completa del comando

(in /home/fespinoza/Workspace/TLI) PGError: ERROR: new encoding (UTF8) is incompatible with the encoding of the template database (SQL_ASCII) HINT: Use the same encoding as in the template database, or use template0 as template. : CREATE DATABASE "System_test" ENCODING = ''unicode'' /home/fespinoza/.rvm/gems/ruby-1.9.2-p180/gems/activerecord-3.0.5/lib/active_record/connection_adapters/abstract_adapter.rb:207:in `rescue in log'' /home/fespinoza/.rvm/gems/ruby-1.9.2-p180/gems/activerecord-3.0.5/lib/active_record/connection_adapters/abstract_adapter.rb:199:in `log'' /home/fespinoza/.rvm/gems/ruby-1.9.2-p180/gems/activerecord-3.0.5/lib/active_record/connection_adapters/postgresql_adapter.rb:493:in `execute'' /home/fespinoza/.rvm/gems/ruby-1.9.2-p180/gems/activerecord-3.0.5/lib/active_record/connection_adapters/postgresql_adapter.rb:572:in `create_database'' /home/fespinoza/.rvm/gems/ruby-1.9.2-p180/gems/activerecord-3.0.5/lib/active_record/railties/databases.rake:92:in `rescue in create_database'' /home/fespinoza/.rvm/gems/ruby-1.9.2-p180/gems/activerecord-3.0.5/lib/active_record/railties/databases.rake:39:in `create_database'' /home/fespinoza/.rvm/gems/ruby-1.9.2-p180/gems/activerecord-3.0.5/lib/active_record/railties/databases.rake:33:in `block (2 levels) in <top (required)>'' /home/fespinoza/.rvm/gems/ruby-1.9.2-p180/gems/rake-0.8.7/lib/rake.rb:636:in `call'' /home/fespinoza/.rvm/gems/ruby-1.9.2-p180/gems/rake-0.8.7/lib/rake.rb:636:in `block in execute'' /home/fespinoza/.rvm/gems/ruby-1.9.2-p180/gems/rake-0.8.7/lib/rake.rb:631:in `each'' /home/fespinoza/.rvm/gems/ruby-1.9.2-p180/gems/rake-0.8.7/lib/rake.rb:631:in `execute'' /home/fespinoza/.rvm/gems/ruby-1.9.2-p180/gems/rake-0.8.7/lib/rake.rb:597:in `block in invoke_with_call_chain'' /home/fespinoza/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/1.9.1/monitor.rb:201:in `mon_synchronize'' /home/fespinoza/.rvm/gems/ruby-1.9.2-p180/gems/rake-0.8.7/lib/rake.rb:590:in `invoke_with_call_chain'' /home/fespinoza/.rvm/gems/ruby-1.9.2-p180/gems/rake-0.8.7/lib/rake.rb:583:in `invoke'' /home/fespinoza/.rvm/gems/ruby-1.9.2-p180/gems/rake-0.8.7/lib/rake.rb:2051:in `invoke_task'' /home/fespinoza/.rvm/gems/ruby-1.9.2-p180/gems/rake-0.8.7/lib/rake.rb:2029:in `block (2 levels) in top_level'' /home/fespinoza/.rvm/gems/ruby-1.9.2-p180/gems/rake-0.8.7/lib/rake.rb:2029:in `each'' /home/fespinoza/.rvm/gems/ruby-1.9.2-p180/gems/rake-0.8.7/lib/rake.rb:2029:in `block in top_level'' /home/fespinoza/.rvm/gems/ruby-1.9.2-p180/gems/rake-0.8.7/lib/rake.rb:2068:in `standard_exception_handling'' /home/fespinoza/.rvm/gems/ruby-1.9.2-p180/gems/rake-0.8.7/lib/rake.rb:2023:in `top_level'' /home/fespinoza/.rvm/gems/ruby-1.9.2-p180/gems/rake-0.8.7/lib/rake.rb:2001:in `block in run'' /home/fespinoza/.rvm/gems/ruby-1.9.2-p180/gems/rake-0.8.7/lib/rake.rb:2068:in `standard_exception_handling'' /home/fespinoza/.rvm/gems/ruby-1.9.2-p180/gems/rake-0.8.7/lib/rake.rb:1998:in `run'' /home/fespinoza/.rvm/gems/ruby-1.9.2-p180/gems/rake-0.8.7/bin/rake:31:in `<top (required)>'' /home/fespinoza/.rvm/gems/ruby-1.9.2-p180/bin/rake:19:in `load'' /home/fespinoza/.rvm/gems/ruby-1.9.2-p180/bin/rake:19:in `<main>'' Couldn''t create database for {"adapter"=>"postgresql", "encoding"=>"unicode", "database"=>"System_test", "pool"=>5, "username"=>"forellana", "password"=>nil} PGError: ERROR: new encoding (UTF8) is incompatible with the encoding of the template database (SQL_ASCII) HINT: Use the same encoding as in the template database, or use template0 as template. : CREATE DATABASE "System_development" ENCODING = ''unicode'' /home/fespinoza/.rvm/gems/ruby-1.9.2-p180/gems/activerecord-3.0.5/lib/active_record/connection_adapters/abstract_adapter.rb:207:in `rescue in log'' /home/fespinoza/.rvm/gems/ruby-1.9.2-p180/gems/activerecord-3.0.5/lib/active_record/connection_adapters/abstract_adapter.rb:199:in `log'' /home/fespinoza/.rvm/gems/ruby-1.9.2-p180/gems/activerecord-3.0.5/lib/active_record/connection_adapters/postgresql_adapter.rb:493:in `execute'' /home/fespinoza/.rvm/gems/ruby-1.9.2-p180/gems/activerecord-3.0.5/lib/active_record/connection_adapters/postgresql_adapter.rb:572:in `create_database'' /home/fespinoza/.rvm/gems/ruby-1.9.2-p180/gems/activerecord-3.0.5/lib/active_record/railties/databases.rake:92:in `rescue in create_database'' /home/fespinoza/.rvm/gems/ruby-1.9.2-p180/gems/activerecord-3.0.5/lib/active_record/railties/databases.rake:39:in `create_database'' /home/fespinoza/.rvm/gems/ruby-1.9.2-p180/gems/activerecord-3.0.5/lib/active_record/railties/databases.rake:35:in `block (2 levels) in <top (required)>'' /home/fespinoza/.rvm/gems/ruby-1.9.2-p180/gems/rake-0.8.7/lib/rake.rb:636:in `call'' /home/fespinoza/.rvm/gems/ruby-1.9.2-p180/gems/rake-0.8.7/lib/rake.rb:636:in `block in execute'' /home/fespinoza/.rvm/gems/ruby-1.9.2-p180/gems/rake-0.8.7/lib/rake.rb:631:in `each'' /home/fespinoza/.rvm/gems/ruby-1.9.2-p180/gems/rake-0.8.7/lib/rake.rb:631:in `execute'' /home/fespinoza/.rvm/gems/ruby-1.9.2-p180/gems/rake-0.8.7/lib/rake.rb:597:in `block in invoke_with_call_chain'' /home/fespinoza/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/1.9.1/monitor.rb:201:in `mon_synchronize'' /home/fespinoza/.rvm/gems/ruby-1.9.2-p180/gems/rake-0.8.7/lib/rake.rb:590:in `invoke_with_call_chain'' /home/fespinoza/.rvm/gems/ruby-1.9.2-p180/gems/rake-0.8.7/lib/rake.rb:583:in `invoke'' /home/fespinoza/.rvm/gems/ruby-1.9.2-p180/gems/rake-0.8.7/lib/rake.rb:2051:in `invoke_task'' /home/fespinoza/.rvm/gems/ruby-1.9.2-p180/gems/rake-0.8.7/lib/rake.rb:2029:in `block (2 levels) in top_level'' /home/fespinoza/.rvm/gems/ruby-1.9.2-p180/gems/rake-0.8.7/lib/rake.rb:2029:in `each'' /home/fespinoza/.rvm/gems/ruby-1.9.2-p180/gems/rake-0.8.7/lib/rake.rb:2029:in `block in top_level'' /home/fespinoza/.rvm/gems/ruby-1.9.2-p180/gems/rake-0.8.7/lib/rake.rb:2068:in `standard_exception_handling'' /home/fespinoza/.rvm/gems/ruby-1.9.2-p180/gems/rake-0.8.7/lib/rake.rb:2023:in `top_level'' /home/fespinoza/.rvm/gems/ruby-1.9.2-p180/gems/rake-0.8.7/lib/rake.rb:2001:in `block in run'' /home/fespinoza/.rvm/gems/ruby-1.9.2-p180/gems/rake-0.8.7/lib/rake.rb:2068:in `standard_exception_handling'' /home/fespinoza/.rvm/gems/ruby-1.9.2-p180/gems/rake-0.8.7/lib/rake.rb:1998:in `run'' /home/fespinoza/.rvm/gems/ruby-1.9.2-p180/gems/rake-0.8.7/bin/rake:31:in `<top (required)>'' /home/fespinoza/.rvm/gems/ruby-1.9.2-p180/bin/rake:19:in `load'' /home/fespinoza/.rvm/gems/ruby-1.9.2-p180/bin/rake:19:in `<main>'' Couldn''t create database for {"adapter"=>"postgresql", "encoding"=>"unicode", "database"=>"System_development", "pool"=>5, "username"=>"forellana", "password"=>nil}


Al igual que las otras respuestas, encontré que esta idea fue muy útil. Usando Ubuntu 14.04. Quería cambiar la plantilla predeterminada para usar UTF-8.

Entrar en el prompt de postgres:

Activate the postgres console. su - postgres psql

Luego escribe los siguientes comandos:

# First, we need to drop template1. Templates can’t be dropped, so we first modify it so t’s an ordinary database: UPDATE pg_database SET datistemplate = FALSE WHERE datname = ''template1''; # Now we can drop it: DROP DATABASE template1; # Now its time to create database from template0, with a new default encoding: CREATE DATABASE template1 WITH TEMPLATE = template0 ENCODING = ''UNICODE''; # Now modify template1 so it’s actually a template: UPDATE pg_database SET datistemplate = TRUE WHERE datname = ''template1''; # Now switch to template1 and VACUUM FREEZE the template: /c template1 VACUUM FREEZE;

El problema debe ser resuelto. Créditos a: https://gist.github.com/amolkhanorkar-webonise/8706915


El principal problema aquí es que su plantilla de base de datos ( template1 ) se ha creado con una codificación ASCII y le está diciendo a PostgreSQL que cree la nueva base de datos con codificación UTF8. No hace falta decir que no está particularmente satisfecho con eso. Lo que puede hacer es borrar su base de datos template1 y volver a crearla usando estas instrucciones . Esto también puede ser un problema cuando su proveedor de alojamiento no ha configurado correctamente la configuración regional. Puede leer más sobre cómo arreglar sus configuraciones locales faltantes .

Encontré toda esta información a través de esta publicación sobre la fijación de la codificación predeterminada de PostgreSQL en Ubuntu 9.10



Puede cambiar la plantilla postgres1 para que sea UTF haciendo lo siguiente tal como se publica here:

UPDATE pg_database SET datistemplate = FALSE WHERE datname = ''template1''; DROP DATABASE template1; CREATE DATABASE template1 WITH TEMPLATE = template0 ENCODING = ''UNICODE''; UPDATE pg_database SET datistemplate = TRUE WHERE datname = ''template1''; /c template1 VACUUM FREEZE; UPDATE pg_database SET datallowconn = FALSE WHERE datname = ''template1'';