Ruby on Rails Friday, April 7, 2017



On Friday, April 7, 2017 at 4:05:05 PM UTC-4, Rob Biedenharn wrote:

On 2017-Apr-7, at 15:26 , fugee ohu <fuge...@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-line
  create_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

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)

Where can I read how to set autoincrement and primary key values for mysql at the server level 

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/96f28157-b402-479e-a35c-a818b00e0217%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment