So I'm new to ROR and Heroku and need a little help. I've created an app and have deployed it; however, I'd like to clear out the database associated with it. Meaning I'd like to clear any users (and their attached data) that have been created thus far.
所以我是ROR和Heroku的新手,需要一些帮助。我已经创建了一个应用并部署了它;但是,我想清除与它相关的数据库。也就是说,我希望清除到目前为止创建的所有用户(以及他们的附加数据)。
I've basically created several phony accounts to test out whether the database on the production site works, but now i'd like to clear this out, and start with a fresh database.
我基本上已经创建了几个伪造的帐户来测试生产站点上的数据库是否正常工作,但是现在我想清除这些帐户,并从一个新的数据库开始。
Is this possible without deleting the database entirely?
如果不完全删除数据库,这是可能的吗?
Any help would be sincerely appreciated. Thank you very much for your time!
任何帮助都将得到衷心的感谢。非常感谢您的时间!
10 个解决方案
#1
52
You can use heroku pg:reset DATABASE
command to reset the entire database. The command will simply drop and create the database.
您可以使用heroku pg:reset DATABASE命令来重置整个数据库。该命令将简单地删除并创建数据库。
You have to use heroku rake db:migrate
to create the tables then.
您必须使用heroku rake db:migrate to create the tables。
Alternatively you can use rake db:reset
command locally and then run heroku db:push
to update the production db.
您也可以在本地使用rake db:reset命令,然后运行heroku db:push来更新生产db。
#2
9
Login on Heroku through terminal and then run one of following commands:
通过终端登录Heroku,然后运行以下命令:
heroku rake db:reset
//or:
heroku run rake db:reset
The first one is an old one and the second is latest.
第一个是旧的,第二个是最新的。
#3
8
heroku pg:reset DATABASE --confirm {app-name}
heroku run rake db:migrate
heroku run rake db:seed
#4
7
The 2013 way to do this is:
2013年的做法是:
Enter heroku pg:reset DATABASE
in your console and then enter in your app name when prompted. This will drop the entire database -- tables, rows, columns, all of its data, everything.
输入heroku pg:在控制台重置数据库,然后在提示时输入应用程序名。这将删除整个数据库——表、行、列、它的所有数据和所有内容。
Then, enter heroku run rake db:migrate
. This will create the same table, rows, and columns, but without any object data.
然后输入heroku run rake db:migrate。这将创建相同的表、行和列,但是没有任何对象数据。
#5
3
The current way is:
目前的方法是:
heroku pg:reset DATABASE_URL --confirm <APP_NAME>
#6
2
The current Cedar stack's proper syntax for shared databases is:
当前雪松栈对共享数据库的正确语法是:
heroku pg:reset SHARED_DATABASE my-database-name-1294
(Replace "my-database-name-1294" with whatever is before the .herokuapp.com in your URL)
(将“my-database-name-1294”替换为URL中。herokuapp.com之前的内容)
It'll then ask you this:
然后它会问你:
----> Resetting SHARED_DATABASE (DATABASE_URL)
! WARNING: Potentially Destructive Action
! This command will affect the app: my-database-name-1294
! To proceed, type "my-database-name-1294" or re-run this command with --confirm my-database-name-1294
Just retype "my-database-name-1294" there and it'll reset everything.
只要在那里重新输入“my-database-name-1294”,它就会重置一切。
#7
2
To reset your database
重置您的数据库
run like bellow
像风箱
heroku pg:reset SHARED_DATABASE --confirm APP_NAME
heroku pg:重置SHARED_DATABASE——确认APP_NAME
this works very well for my
这对我来说效果很好
#8
1
Yes, you can either use SQL methods to do it or perhaps just use the Rails Console to do it from the command line and call the @users.destroy_all method. This article explains how to use the console from Heroku.
是的,您可以使用SQL方法来完成它,也可以使用Rails控制台从命令行完成它,并调用@ users.驱逐舰_all方法。本文解释如何使用来自Heroku的控制台。
#9
1
If you have two servers - production and staging, and you want to add the database from production to staging
如果您有两个服务器——生产和登台,并且您希望将数据库从生产添加到登台
heroku pg:reset DATABASE --remote staging
heroku pgbackups:restore DATABASE URL_OF_DATABASE --remote staging
heroku run rake db:migrate --remote staging
URL_TO_DATABASE - an aws or dropbox url for the dump.
URL_TO_DATABASE -一个aws或dropbox url的转储。
This worked for me!
这为我工作!
#10
0
Heroku provides a visual tool to do this. Go to Resources > Heroku Postgres :: Database Drop database manualy
Heroku提供了一个可视化工具。转到参考资料> Heroku Postgres:数据库删除数据库手册
If you want to migrate your tables use rake db:migrate
To launch your seeds rake db:seed
如果您想迁移您的表使用rake db:迁移来启动您的种子rake db:seed。
#1
52
You can use heroku pg:reset DATABASE
command to reset the entire database. The command will simply drop and create the database.
您可以使用heroku pg:reset DATABASE命令来重置整个数据库。该命令将简单地删除并创建数据库。
You have to use heroku rake db:migrate
to create the tables then.
您必须使用heroku rake db:migrate to create the tables。
Alternatively you can use rake db:reset
command locally and then run heroku db:push
to update the production db.
您也可以在本地使用rake db:reset命令,然后运行heroku db:push来更新生产db。
#2
9
Login on Heroku through terminal and then run one of following commands:
通过终端登录Heroku,然后运行以下命令:
heroku rake db:reset
//or:
heroku run rake db:reset
The first one is an old one and the second is latest.
第一个是旧的,第二个是最新的。
#3
8
heroku pg:reset DATABASE --confirm {app-name}
heroku run rake db:migrate
heroku run rake db:seed
#4
7
The 2013 way to do this is:
2013年的做法是:
Enter heroku pg:reset DATABASE
in your console and then enter in your app name when prompted. This will drop the entire database -- tables, rows, columns, all of its data, everything.
输入heroku pg:在控制台重置数据库,然后在提示时输入应用程序名。这将删除整个数据库——表、行、列、它的所有数据和所有内容。
Then, enter heroku run rake db:migrate
. This will create the same table, rows, and columns, but without any object data.
然后输入heroku run rake db:migrate。这将创建相同的表、行和列,但是没有任何对象数据。
#5
3
The current way is:
目前的方法是:
heroku pg:reset DATABASE_URL --confirm <APP_NAME>
#6
2
The current Cedar stack's proper syntax for shared databases is:
当前雪松栈对共享数据库的正确语法是:
heroku pg:reset SHARED_DATABASE my-database-name-1294
(Replace "my-database-name-1294" with whatever is before the .herokuapp.com in your URL)
(将“my-database-name-1294”替换为URL中。herokuapp.com之前的内容)
It'll then ask you this:
然后它会问你:
----> Resetting SHARED_DATABASE (DATABASE_URL)
! WARNING: Potentially Destructive Action
! This command will affect the app: my-database-name-1294
! To proceed, type "my-database-name-1294" or re-run this command with --confirm my-database-name-1294
Just retype "my-database-name-1294" there and it'll reset everything.
只要在那里重新输入“my-database-name-1294”,它就会重置一切。
#7
2
To reset your database
重置您的数据库
run like bellow
像风箱
heroku pg:reset SHARED_DATABASE --confirm APP_NAME
heroku pg:重置SHARED_DATABASE——确认APP_NAME
this works very well for my
这对我来说效果很好
#8
1
Yes, you can either use SQL methods to do it or perhaps just use the Rails Console to do it from the command line and call the @users.destroy_all method. This article explains how to use the console from Heroku.
是的,您可以使用SQL方法来完成它,也可以使用Rails控制台从命令行完成它,并调用@ users.驱逐舰_all方法。本文解释如何使用来自Heroku的控制台。
#9
1
If you have two servers - production and staging, and you want to add the database from production to staging
如果您有两个服务器——生产和登台,并且您希望将数据库从生产添加到登台
heroku pg:reset DATABASE --remote staging
heroku pgbackups:restore DATABASE URL_OF_DATABASE --remote staging
heroku run rake db:migrate --remote staging
URL_TO_DATABASE - an aws or dropbox url for the dump.
URL_TO_DATABASE -一个aws或dropbox url的转储。
This worked for me!
这为我工作!
#10
0
Heroku provides a visual tool to do this. Go to Resources > Heroku Postgres :: Database Drop database manualy
Heroku提供了一个可视化工具。转到参考资料> Heroku Postgres:数据库删除数据库手册
If you want to migrate your tables use rake db:migrate
To launch your seeds rake db:seed
如果您想迁移您的表使用rake db:迁移来启动您的种子rake db:seed。