What to do if you accidentally create a model

Conclusion

Specify only the model and delete it as shown below.

Terminal


rails destroy model [Model name]

This is the command because you don't need to specify any columns when you drop the model.

However, if you have done rails db: migrate, you have created a table, so you should delete the table just in case.

How to delete a table

Edit the migration file

Change the part of create_table: comments to drop_table: comments.

class CreateComments < ActiveRecord::Migration[6.0]
  def change
    create_table :comments do |t|
      t.string :content
    end
  end

Finally, type the following command in the terminal to delete the table from the data veil.

rails db:migrate

Reference article

[Rails] Model Delete Command Delete table in Rails

Recommended Posts

What to do if you accidentally create a model
What to do if you get a java.io.IOException in GlassFish
# What to do if you accidentally do rails db: migrate: drop
What to do if you install Ubuntu
What to do if you get a gcc error in Docker
What to do if you get a DISPLAY error in gym.render ()
What to do if you push incorrect information
What to do if you get a groovy warning in Thymeleaf Layout
What to do if you get a MiniMagick vulnerability alert on GitHub
What to do if you get a SQLite3 :: BusyException: database is locked error
What to do if mysql2 gets a bundle install error
What to do if you can't use the rails command
What to do if you get a wrong number of arguments error in binding.pry
What to do if you get a NoClassDefFoundError when trying to run eclipse on Java9
What to do if you get a port error when docker-compose up on Mac
What to do when a javax.el.PropertyNotWritableException occurs
What to do if you get a "Cannot Pull Container Error" when starting ECS ​​Fargate
What to do if you get angry with OpenSSL with pyenv install
What to do if you get a "302" error in your controller unit test code in Rails
What to do when you become a Problem During Content Assist
What to do when you run into a docker-compose node_modules problem
What to do if you forget the root password in CentOS7
What to do if you cannot roll back the migration (UnknownMigrationVersionError)
[Rails] What to do if you can't get parameters with form_with
What to do if you get a "Mysql2 :: Error: Operand should contain 1 column (s)" error in Rails
What to do if you get a JNI shared library error when trying to build in Eclipse
[Output] Learn Ruby from what you want to do at the fastest speed-Part 2 "Create a flowchart"
What to do if you get an error during rails db: reset
[Composer] [Laravel] What to do if you cannot install due to insufficient memory
What to do if you can't install the plugin from the Eclipse marketplace
What to do if you don't like the code generated by swagger-codegen-cli
What to do if you get an error when you hit Heroku logs
What to do if the server tomcat dies
What to do if mvn archetype: generate fails
What do you use when converting to String?
What to do if Operation not permitted is displayed when you execute a command in the terminal
What to do if you get Could not locate Gemfile or .bundle / directory
<f: ajax> Unable to attach <f: ajax> to non-ClientBehaviorHolder What to do when you become a parent
What to do if you can't activate the select box created by bootstrap-select
What to do if you have installed Java for OS X on macOS
What to do if you get an error on heroku rake db: migrate
What to do if you get angry if you don't have nokogiri while installing wp2txt
What to do if you get To install the missing version, run `gem install bundler: 2.1.4`
What to do if the debug gem installation fails
What to do if the Rails server can't start
What to do if ClassNotFoundException occurs when starting Tomcat
What to do if rails server can't be stopped
What to do if TextToSpeech doesn't work on Android 11
Reasons to include ActiveModel :: Model to create a Form object
What to do if you get a javax.net.ssl.SSLHandshakeException: Remote host closed connection during handshake in the IBM JDK
What to do when a null byte error occurs
What to do if you get Could not save master table to file after importing a project in Eclipse
What to do when rails creates a 〇〇 2.rb file
What to do if an ActionController :: UnknownFormat error occurs
What to do if password authentication fails in Docker/Postgres
What to do if you can't get the text of an element in Selenium
What to do if you get the error Couldn't find Item without an ID
What to do if you can't find your API key after deploying to Rails heroku
What to do if you cannot execute with the command "Java package name / class name"
What to do if you get an error saying "Please enter a valid value" when getting with Rails datetime_field
What to do if you get an error saying "Could not find a JavaScript runtime." When starting rails server