I have followed this but can’t alter the schema of my Database. Following is the step I followed-
0- Run the mix ecto.gen.migration create_contracts. So got an error of existing migration file.
1- Deleted the **_migration_file which was stored in the repo/migrations
2- run the mix ecto.gen.migration create_contracts . So, a migration file is created.
3- run the mix ecto.migrate. Got an error- (Postgrex.Error) ERROR 42P07 (duplicate_table) relation "contracts" already exists.
Here is my schema-
schema "contracts" do
field :Category, :string
field :Cost, :decimal
field :EndsOn, :date
field :Vendor, :string
timestamps()
end
Firstly, I want to lowercase the column name and secondly, I want to change the type as well. Any response to alter/modify the schema of the database will be highly appreciated.
Nothing changes. See the screenshot
Two things to note-
–I have modified the **_migration_file manually when I was trying myself in starting(before posting the question here).
–The screenshot which I have shared, there the migration number on generated file(see terminal) is different from what I have opened in VS code.
Firstly, I don’t know to stop the server so when you said then I stop the local server by pressing ctrl + c x 2. After this, i hit the 3 commands you mention above.
Yes, this is what I mean… pressing ctrl-c twice should stop the server. But You need to close any other applications accessing the database, that could be a terminal with psql open, or any server instance.
How to do that?
One thing more, When I inspect struct of the schema. There was no change. This struct of schema was right now inserted. Check screenshot
See the 2nd last line of the screenshot. You will found those Uppercase Column Name.
The post You follow is from 2016, it is using the old phoenix version.
It is also using gen.html, which generates for You a lot of files.
You should use phx instead…
$ mix help | grep phx
mix local.phx # Updates the Phoenix project generator locally
mix phx # Prints Phoenix help information
mix phx.digest # Digests and compresses static files
mix phx.digest.clean # Removes old versions of static assets.
mix phx.gen.cert # Generates a self-signed certificate for HTTPS testing
mix phx.gen.channel # Generates a Phoenix channel
mix phx.gen.context # Generates a context with functions around an Ecto schema
mix phx.gen.embedded # Generates an embedded Ecto schema file
mix phx.gen.html # Generates controller, views, and context for an HTML resource
mix phx.gen.json # Generates controller, views, and context for a JSON resource
mix phx.gen.presence # Generates a Presence tracker
mix phx.gen.schema # Generates an Ecto schema and migration file
mix phx.gen.secret # Generates a secret
mix phx.new # Creates a new Phoenix v1.4.2 application
mix phx.new.ecto # Creates a new Ecto project within an umbrella project
mix phx.new.web # Creates a new Phoenix web project within an umbrella project
mix phx.routes # Prints all routes
mix phx.server # Starts applications and their servers