首頁 資料庫 mysql教程 rake db数据库操作整理

rake db数据库操作整理

Jun 07, 2016 pm 03:37 PM
utf8 創建 操作 支援 數位 資料庫 整理 預設

创建默认支持utf8的数据库 createdatabasedb1defaultcharactersetutf8; 命令行 rakedb:***** script/generatemodeltaskname:stringpriority:integer script/generatemigrationadd_description_to_taskdescription:string script/generatemigrationremove_de

创建默认支持utf8的数据库

create database db1 default character set utf8;


命令行 
rake db:*****
script/generate model task name:string priority:integer   
script/generate migration add_description_to_task description:string   
script/generate migration remove_description_from_task description:string 

数据类型 
引用
# :string, :text, :integer, :float,:decimal, :datetime, :timestamp, :time, :date, 
# :binary, :boolean 

与db有关的rake任务 
 
db:charset 检索当前环境下数据库的字符设置   
db:collation 检索当前环境下数据库的校对   
db:create 用config\database.yml中的定义创建当前 RAILS_ENV 项目环境下的数据库   
db:create:all 用config\database.yml中的定义创建所有数据库   
db:drop 删除当前 RAILS_ENV项目环境中的数据库   
db:drop:all 删除所有在 config\database.yml中定义的数据库   
db:reset 从db\schema.rb中为当前环境重建数据库(先删后建).   
db:rollback 回滚(清华出版社一本SQLSERVER书的名词[很奇怪为什么不直接用滚回])数据库到前一个版本. 指定回滚到哪一步要用 STEP=n 参数   
db:version 检索当前模式下的版本   

备份数据库
rake db:backup:create 根据database.yml的信息备份数据库
rake db:backup:destroy 默认删除一天前的备份数据
rake db:backup:rebuild 默认恢复最新的备份数据

注意:这里设置的备份目录是db的backup目录,可以修改 

添加索引 
引用

add_index :acls, ["action_id","group_id"],:unique=>true 
add_index :acls, :action_id 

drop all tables 删除全部表
rake db:migrate VERSION=0  

指定恢复/删除:
rake db:migrate:down/up VERSION = version_of_migrati

定义数字精确度 
t.integer :total_price, :precision=>8,:scale=>2,:default=>0


========================================================================================================================================================
rake db:abort_if_pending_migrations  # Raises an error if there are pending migrations
rake db:charset                      # Retrieves the charset for the current environment's database
rake db:collation                    # Retrieves the collation for the current environment's database
rake db:create                       # Create the database defined in config/database.yml for the current RAILS_ENV
rake db:create:all                   # Create all the local databases defined in config/database.yml
rake db:drop                         # Drops the database for the current RAILS_ENV
rake db:drop:all                     # Drops all the local databases defined in config/database.yml
rake db:fixtures:identify            # Search for a fixture given a LABEL or ID.
rake db:fixtures:load                # Load fixtures into the current environment's database.
rake db:migrate                      # Migrate the database through scripts in db/migrate.
rake db:migrate:down                 # Runs the "down" for a given migration VERSION.
rake db:migrate:redo                 # Rollbacks the database one migration and re migrate up.
rake db:migrate:reset                # Resets your database using your migrations for the current environment
rake db:migrate:up                   # Runs the "up" for a given migration VERSION.
rake db:reset                        # Drops and recreates the database from db/schema.rb for the current environment.
rake db:rollback                     # Rolls the schema back to the previous version.
rake db:schema:dump                  # Create a db/schema.rb file that can be portably used against any DB supported by AR
rake db:schema:load                  # Load a schema.rb file into the database
rake db:sessions:clear               # Clear the sessions table
rake db:sessions:create              # Creates a sessions migration for use with CGI::Session::ActiveRecordStore
rake db:structure:dump               # Dump the database structure to a SQL file
rake db:test:clone                   # Recreate the test database from the current environment's database schema
rake db:test:clone_structure         # Recreate the test databases from the development structure
rake db:test:load                    # Recreate the test database from the current schema.rb
rake db:test:prepare                 # Check for pending migrations and load the test schema
rake db:test:purge                   # Empty the test database
rake db:version                      # Retrieves the current schema version number
rake doc:app                         # Build the app HTML Files
rake doc:clobber_app                 # Remove rdoc products
rake doc:clobber_plugins             # Remove plugin documentation
rake doc:clobber_rails               # Remove rdoc products
rake doc:guides                      # Generate Rails guides
rake doc:plugins                     # Generate documentation for all installed plugins
rake doc:rails                       # Build the rails HTML Files
rake doc:reapp                       # Force a rebuild of the RDOC files
rake doc:rerails                     # Force a rebuild of the RDOC files
rake gems                            # List the gems that this rails application depends on
rake gems:build                      # Build any native extensions for unpacked gems
rake gems:install                    # Installs all required gems for this application.
rake gems:refresh_specs              # Regenerate gem specifications in correct format.
rake gems:unpack                     # Unpacks the specified gem into vendor/gems.
rake gems:unpack:dependencies        # Unpacks the specified gems and its dependencies into vendor/gems
rake log:clear                       # Truncates all *.log files in log/ to zero bytes
rake notes                           # Enumerate all annotations
rake notes:custom                    # Enumerate a custom annotation, specify with ANNOTATION=WTFHAX
rake notes:fixme                     # Enumerate all FIXME annotations
rake notes:optimize                  # Enumerate all OPTIMIZE annotations
rake notes:todo                      # Enumerate all TODO annotations
rake rails:freeze:edge               # Lock to latest Edge Rails, for a specific release use RELEASE=1.2.0
rake rails:freeze:gems               # Lock this application to the current gems (by unpacking them into vendor/rails)
rake rails:unfreeze                  # Unlock this application from freeze of gems or edge and return to a fluid use of system gems
rake rails:update                    # Update both configs, scripts and public/javascripts from Rails
rake rails:update:configs            # Update config/boot.rb from your current rails install
rake rails:update:javascripts        # Update your javascripts from your current rails install
rake rails:update:scripts            # Add new scripts to the application script/ directory
rake routes                          # Print out all defined routes in match order, with names.
rake secret                          # Generate a crytographically secure secret key.
rake stats                           # Report code statistics (KLOCs, etc) from the application
rake test                            # Run all unit, functional and integration tests
rake test:benchmark                  # Run tests for benchmarkdb:test:prepare / Benchmark the performance tests
rake test:functionals                # Run tests for functionalsdb:test:prepare / Run the functional tests in test/functional
rake test:integration                # Run tests for integrationdb:test:prepare / Run the integration tests in test/integration
rake test:plugins                    # Run tests for pluginsenvironment / Run the plugin tests in vendor/plugins/*/**/test (or specify with PLUGIN=name)
rake test:profile                    # Run tests for profiledb:test:prepare / Profile the performance tests
rake test:recent                     # Run tests for recentdb:test:prepare / Test recent changes
rake test:uncommitted                # Run tests for uncommitteddb:test:prepare / Test changes since last checkin (only Subversion and Git)
rake test:units                      # Run tests for unitsdb:test:prepare / Run the unit tests in test/unit
rake time:zones:all                  # Displays names of all time zones recognized by the Rails TimeZone class, grouped by offset.
rake time:zones:local                # Displays names of time zones recognized by the Rails TimeZone class with the same offset as the system local time
rake time:zones:us                   # Displays names of US time zones recognized by the Rails TimeZone class, grouped by offset.
rake tmp:cache:clear                 # Clears all files and directories in tmp/cache
rake tmp:clear                       # Clear session, cache, and socket files from tmp/
rake tmp:create                      # Creates tmp directories for sessions, cache, and sockets
rake tmp:pids:clear                  # Clears all files in tmp/pids
rake tmp:sessions:clear              # Clears all files in tmp/sessions
rake tmp:sockets:clear               # Clears all files in tmp/sockets


本網站聲明
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn

熱AI工具

Undresser.AI Undress

Undresser.AI Undress

人工智慧驅動的應用程序,用於創建逼真的裸體照片

AI Clothes Remover

AI Clothes Remover

用於從照片中去除衣服的線上人工智慧工具。

Undress AI Tool

Undress AI Tool

免費脫衣圖片

Clothoff.io

Clothoff.io

AI脫衣器

Video Face Swap

Video Face Swap

使用我們完全免費的人工智慧換臉工具,輕鬆在任何影片中換臉!

熱工具

記事本++7.3.1

記事本++7.3.1

好用且免費的程式碼編輯器

SublimeText3漢化版

SublimeText3漢化版

中文版,非常好用

禪工作室 13.0.1

禪工作室 13.0.1

強大的PHP整合開發環境

Dreamweaver CS6

Dreamweaver CS6

視覺化網頁開發工具

SublimeText3 Mac版

SublimeText3 Mac版

神級程式碼編輯軟體(SublimeText3)

iOS 18 新增「已復原」相簿功能 可找回遺失或損壞的照片 iOS 18 新增「已復原」相簿功能 可找回遺失或損壞的照片 Jul 18, 2024 am 05:48 AM

蘋果公司最新發布的iOS18、iPadOS18以及macOSSequoia系統為Photos應用程式增添了一項重要功能,旨在幫助用戶輕鬆恢復因各種原因遺失或損壞的照片和影片。這項新功能在Photos應用的"工具"部分引入了一個名為"已恢復"的相冊,當用戶設備中存在未納入其照片庫的圖片或影片時,該相冊將自動顯示。 "已恢復"相簿的出現為因資料庫損壞、相機應用未正確保存至照片庫或第三方應用管理照片庫時照片和視頻丟失提供了解決方案。使用者只需簡單幾步

在PHP中使用MySQLi建立資料庫連線的詳盡教學 在PHP中使用MySQLi建立資料庫連線的詳盡教學 Jun 04, 2024 pm 01:42 PM

如何在PHP中使用MySQLi建立資料庫連線:包含MySQLi擴充(require_once)建立連線函數(functionconnect_to_db)呼叫連線函數($conn=connect_to_db())執行查詢($result=$conn->query())關閉連線( $conn->close())

如何在PHP中處理資料庫連線錯誤 如何在PHP中處理資料庫連線錯誤 Jun 05, 2024 pm 02:16 PM

PHP處理資料庫連線報錯,可以使用下列步驟:使用mysqli_connect_errno()取得錯誤代碼。使用mysqli_connect_error()取得錯誤訊息。透過擷取並記錄這些錯誤訊息,可以輕鬆識別並解決資料庫連接問題,確保應用程式的順暢運作。

Astar質押原理、收益拆解、空投項目及策略 & 操作保姆級攻略 Astar質押原理、收益拆解、空投項目及策略 & 操作保姆級攻略 Jun 25, 2024 pm 07:09 PM

目錄Astar Dapp 質押原理質押收益 拆解潛在空投項目:AlgemNeurolancheHealthreeAstar Degens DAOVeryLongSwap 質押策略 & 操作“AstarDapp質押”今年初已升級至V3版本,對質押收益規則做了不少調整。目前首個質押週期已結束,第二質押週期的「投票」子週期剛開始。若要獲得「額外獎勵」收益,需掌握此關鍵階段(預計持續至6月26日,現餘不到5天)。我將細緻拆解Astar質押收益,

如何在 Golang 中使用資料庫回呼函數? 如何在 Golang 中使用資料庫回呼函數? Jun 03, 2024 pm 02:20 PM

在Golang中使用資料庫回呼函數可以實現:在指定資料庫操作完成後執行自訂程式碼。透過單獨的函數新增自訂行為,無需編寫額外程式碼。回調函數可用於插入、更新、刪除和查詢操作。必須使用sql.Exec、sql.QueryRow或sql.Query函數才能使用回呼函數。

如何在 Golang 中將 JSON 資料保存到資料庫中? 如何在 Golang 中將 JSON 資料保存到資料庫中? Jun 06, 2024 am 11:24 AM

可以透過使用gjson函式庫或json.Unmarshal函數將JSON資料儲存到MySQL資料庫中。 gjson函式庫提供了方便的方法來解析JSON字段,而json.Unmarshal函數需要一個目標類型指標來解組JSON資料。這兩種方法都需要準備SQL語句和執行插入操作來將資料持久化到資料庫中。

全球數字虛擬幣交易平台排行榜前十(2025權威排名) 全球數字虛擬幣交易平台排行榜前十(2025權威排名) Mar 06, 2025 pm 04:36 PM

2025年全球數字虛擬幣交易平台競爭激烈,本文根據交易量、安全性、用戶體驗等指標,權威發布2025年全球十大數字虛擬幣交易平台排行榜。 OKX憑藉強大的技術實力和全球化運營策略居首,Binance以高流動性和低費用緊隨其後。 Gate.io、Coinbase、Kraken等平台憑藉各自優勢穩居前列。榜單涵蓋Huobi、KuCoin、Bitfinex、Crypto.com和Gemini等交易平台,各有特色,但投資需謹慎。選擇平台需考慮安全性、流動性、費用、用戶體驗、幣種選擇及監管合規性等因素,理性投資

PHP 資料庫連線陷阱:避免常見的錯誤和誤區 PHP 資料庫連線陷阱:避免常見的錯誤和誤區 Jun 05, 2024 pm 10:21 PM

若要避免PHP資料庫連線錯誤,請遵循最佳實務:檢查連線錯誤,變數名稱與憑證相符。使用安全儲存或環境變量,避免硬編碼憑證。使用完後關閉連接,防止SQL注入,使用準備好的語句或綁定參數。

See all articles