Ruby on Rails
Friday, April 7, 2017
On 2017-Apr-7, at 15:26 , fugee ohu <fugee279@gmail.com> wrote:
On Friday, April 7, 2017 at 3:02:50 PM UTC-4, Walter Lee Davis wrote:Those options are all part of create database, which you would run once, not on every migration. I have usually seen them set at the server level, in the database's ini file.
Walter
> On Apr 7, 2017, at 2:59 PM, fugee ohu <fuge...@gmail.com> wrote:
>
> Trying to get the right syntax for something like this to put in schema.rb for mysql2
>
> ENGINE=InnoDB DEFAULT CHARSET=utf8 PRIMARY KEY=ID AUTOINCREMENT
>
> this isn't valid syntax, anyone can correct? additionally i want id to be int(11) and i want the sql-mode traditional
>
> thanks in advance
>
Hey Walter thanks, Until I learn how to set the server can you give me the migrations syntax for each create table statement please, i have something in mind similar to this pseudo-linecreate_table "bios", force: :cascade, options: "ENGINE=InnoDB DEFAULT CHARSET=utf8 PRIMARY KEY=ID AUTOINCREMENT" do |t|thanks in advance
Here's an idea for you: Run the migration and then look into the db/schema.rb file and compare that to the migration and to the actual database table.
It would save time for everyone if you tried some of this yourself and then, if it doesn't make sense, you can say what you did, show the output, explain why you are confused (and what you expected), and then ask for help.
-Rob
For example:
In the migration file:
class CreateLanguages < ActiveRecord::Migration
def change
create_table :languages do |t|
t.string :iso
t.string :name
end
add_index :languages, :iso
end
end
db/schema.rb
create_table "languages", force: :cascade, options: "ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci" do |t|
t.string "iso"
t.string "name"
t.index ["iso"], name: "index_languages_on_iso", using: :btree
end
mysql> show create table languages\G
*************************** 1. row ***************************
Table: languages
Create Table: CREATE TABLE `languages` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`iso` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,
`name` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,
PRIMARY KEY (`id`),
KEY `index_languages_on_iso` (`iso`)
) ENGINE=InnoDB AUTO_INCREMENT=34 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci
1 row in set (0.00 sec)
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment