Migration fails when renaming a column
samsamai opened this issue · 3 comments
samsamai commented
Not sure if I should raise this here or ecto_sql but here goes.
I'm migrating an app from postgres to mysql, when running mix ecto.migrate
on the mysql database(10.1.43-MariaDB-cll-lve) I get the following error:
** (MyXQL.Error) (1064) (ER_PARSE_ERROR) You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'COLUMN `password_hash` TO `password`' at line 1
(ecto_sql) lib/ecto/adapters/sql.ex:612: Ecto.Adapters.SQL.raise_sql_call_error/1
(elixir) lib/enum.ex:1336: Enum."-map/2-lists^map/1-0-"/2
(ecto_sql) lib/ecto/adapters/sql.ex:699: Ecto.Adapters.SQL.execute_ddl/4
(ecto_sql) lib/ecto/migration/runner.ex:343: Ecto.Migration.Runner.log_and_execute_ddl/3
(ecto_sql) lib/ecto/migration/runner.ex:117: anonymous fn/6 in Ecto.Migration.Runner.flush/0
(elixir) lib/enum.ex:1948: Enum."-reduce/3-lists^foldl/2-0-"/3
(ecto_sql) lib/ecto/migration/runner.ex:116: Ecto.Migration.Runner.flush/0
(stdlib) timer.erl:166: :timer.tc/1
(ecto_sql) lib/ecto/migration/runner.ex:25: Ecto.Migration.Runner.run/7
(ecto_sql) lib/ecto/migrator.ex:342: Ecto.Migrator.attempt/7
(ecto_sql) lib/ecto/migrator.ex:243: anonymous fn/4 in Ecto.Migrator.do_up/4
(ecto_sql) lib/ecto/migrator.ex:320: Ecto.Migrator.run_maybe_in_transaction/6
(elixir) lib/task/supervised.ex:90: Task.Supervised.invoke_mfa/2
(elixir) lib/task/supervised.ex:35: Task.Supervised.reply/5
(stdlib) proc_lib.erl:249: :proc_lib.init_p_do_apply/3
This is the migration:
defmodule Tempo.Repo.Migrations.RenamePasswordHashToPassword do
use Ecto.Migration
def change do
rename(table("users"), :password_hash, to: :password)
end
end
josevalim commented
Surprisingly, renaming columns is a recently new feature in MySQL. Previously you could do it, but you had to redeclare the column names and types, which was error prone. So if you want to use old MySQL versions, you will have to write this statement by hand by using execute
.
wojtekmach commented
Yup, that would be:
execute "alter table users change column `password_hash` `password` varchar(255)”
… On 31 Jan 2020, at 21:34, José Valim ***@***.***> wrote:
Closed #101 <#101>.
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub <#101?email_source=notifications&email_token=AAASSJ4VAA76JNQEVLFENT3RASDPBA5CNFSM4KONA7VKYY3PNVWWK3TUL52HS4DFWZEXG43VMVCXMZLOORHG65DJMZUWGYLUNFXW5KTDN5WW2ZLOORPWSZGOWK4GSVA#event-2998430036>, or unsubscribe <https://github.com/notifications/unsubscribe-auth/AAASSJ2NBW7BRWHEZGU52WTRASDPBANCNFSM4KONA7VA>.
samsamai commented
Thanks