表中一定数量的柱子后的Activerecord问题 -- mysql 领域 和 activerecord 领域 和 ruby-on-rails-3 领域 相关 的问题

Problems with ActiveRecord after certain amount of columns in table


简体版||繁體版
1
vote

问题

中文

我第一次像一周前一样出现这个问题,我猜这个事实不是很好的解释,主要是因为我无法隔离问题......显然现在我有...但仍然不知道其性质

我有一个如下迁移:

  class CreateUsers < ActiveRecord::Migration   def self.up        create_table :users do |t|               t.references "faculty"          t.references "department"          t.references "role", :null => false         t.string "name", :null => false, :limit => 20          t.string "surname", :null => false, :limit => 20         t.string "username",:null => false, :limit => 25         t.string "study_group",:limit => 6         t.string "study_course",:limit => 50         t.string "card_code",:limit => 12         t.boolean "During_Day",:default => false         t.string "email", :limit => 100          t.string "hashed_password", :limit => 40                     t.string "salt", :limit => 40                end        end    def self.down     drop_table :users   end end   

如果我开始从Rails控制台创建用户并在尝试通过

恢复数据时保存
    User.all     

某些字段的信息将被损坏。我开始删除字段,并且当我离开前8列(包括默认创建的ID)时,它就会工作。创建第九列或更损害所有内容"在我的观点中获得所有不正确的信息。 我必须说什么时候从铁路控制台我保存一些东西然后从mysql命令行检查它,那么信息很好....所以astivecord丢失了什么?

输出:

你可以从mysql控制台运行 show create table usersG 吗?

    mysql> show create table usersG   *************************** 1. row ***************************        Table: users   Create Table: CREATE TABLE `users` (   `id` int(11) NOT NULL auto_increment,   `faculty_id` int(11) default NULL,   `department_id` int(11) default NULL,   `role_id` int(11) NOT NULL,   `name` varchar(20) NOT NULL,   `surname` varchar(20) NOT NULL,   `username` varchar(25) NOT NULL,   `study_group` varchar(6) default NULL,   `study_course` varchar(50) default NULL,   `card_code` varchar(15) default NULL,   `day_time` tinyint(1) default '0',   `email` varchar(100) default NULL,   `hashed_password` varchar(40) default NULL,   `salt` varchar(40) default NULL,   PRIMARY KEY  (`id`),   KEY `faculty` (`faculty_id`),   KEY `department` (`department_id`),   KEY `role` (`role_id`),   KEY `username` (`username`)  ) ENGINE=InnoDB DEFAULT CHARSET=utf8  1 row in set (0.02 sec)  mysql>   

从rails控制台添加用户

  Loading development environment (Rails 3.0.3) irb(main):001:0> me = User.new => #<User id: nil, faculty_id: nil, department_id: nil, role_id: nil, name: "", surname: "", username: "", study_group: nil, study_cour se: nil, card_code: nil, day_time: false, email: nil, hashed_password: nil, salt: nil> irb(main):002:0> me.name = 'Daniel' => "Daniel" irb(main):003:0> me.surname = 'Garcia' => "Garcia" irb(main):004:0> me.username = 'vinagrito' => "vinagrito" irb(main):005:0> me.role_id = 1 => 1 irb(main):006:0> me.save => false irb(main):007:0> me.errors => {:password=>["is too short (minimum is 8 characters)"], :email=>["is invalid", "can't be blank"]} irb(main):008:0> me.password = '12345678' => "12345678" irb(main):009:0> me.email = 'mail@mail.com' => "mail@mail.com" irb(main):010:0> me.save => true irb(main):011:0> me => #<User id: 2, faculty_id: nil, department_id: nil, role_id: 1, name: "Daniel", surname: "Garcia", username: "vinagrito", study_group : nil, study_course: nil, card_code: nil, day_time: false, email: "mail@mail.com", hashed_password: "6305ee7016b263c0ec41a81439a378837a 318035", salt: "5c33e8fed10b87c9f4b7841f0faeb7b10424289a">    irb(main):013:0> user = User.where(:id => 2) => [#<User id: 2, faculty_id: nil, department_id: nil, role_id: 1, name: "Daniel", surname: "Garcia", username: "vinagrito", study_grou p: nil, study_course: nil, card_code: nil, day_time: false, email: "mail@mail.com", hashed_password: 6305.0, salt: "5c33e8fed10b87c9f4b 7841f0faeb7b10424289a">]   

查看它返回给我的"hashed_pa​​ssword"

开发的输出.log

  <?xml version='1.0' encoding='UTF-8'?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">     <xsl:template match="/">         <FMPXMLRESULT xmlns="http://www.filemaker.com/fmpxmlresult">             <METADATA>                 <FIELD NAME="ID" TYPE="TEXT"/>                 <FIELD NAME="Name" TYPE="TEXT"/>                 <FIELD NAME="Email" TYPE="TEXT"/>                 <FIELD NAME="Mr_Mrs" TYPE="TEXT"/>             </METADATA>             <RESULTSET>                 <xsl:for-each select="PagedResult/Results/Subscriber">                     <ROW>                         <COL>                             <DATA>*This Is Where I'm Stuck*</DATA>                         </COL>                         <COL>                             <DATA><xsl:value-of select="Name/text()"/></DATA>                         </COL>                         <COL>                             <DATA><xsl:value-of select="EmailAddress/text()"/></DATA>                         </COL>                         <COL>                             <DATA>*This Is Where I'm Stuck*</DATA>                         </COL>                     </ROW>                 </xsl:for-each>             </RESULTSET>         </FMPXMLRESULT>     </xsl:template> </xsl:stylesheet> 0  
英文原文

I first had this problem like a week ago and I guess the fact wasn't very well explained mainly because I couldn't isolate the problem...apparently now I have...but still don't know its nature

I have a migration that goes like:

class CreateUsers < ActiveRecord::Migration   def self.up        create_table :users do |t|               t.references "faculty"          t.references "department"          t.references "role", :null => false         t.string "name", :null => false, :limit => 20          t.string "surname", :null => false, :limit => 20         t.string "username",:null => false, :limit => 25         t.string "study_group",:limit => 6         t.string "study_course",:limit => 50         t.string "card_code",:limit => 12         t.boolean "During_Day",:default => false         t.string "email", :limit => 100          t.string "hashed_password", :limit => 40                     t.string "salt", :limit => 40                end        end    def self.down     drop_table :users   end end 

If I start to create users from the rails console and save them when trying to recover the data through

  User.all   

some fields' info would be corrupted.I started to remove fields and it works when I leave the first 8 columns (including the ID which is created by default).Creating a ninth column or even more would damage everything and afterwards I'm getting all kind of not correct information in my views. I must say that when from the rails console I save something and then check it from the mysql command line then the info is fine....so what's ActiveRecord missing?

output for:

Could you run show create table users\G from mysql console?

  mysql> show create table users\G   *************************** 1. row ***************************        Table: users   Create Table: CREATE TABLE `users` (   `id` int(11) NOT NULL auto_increment,   `faculty_id` int(11) default NULL,   `department_id` int(11) default NULL,   `role_id` int(11) NOT NULL,   `name` varchar(20) NOT NULL,   `surname` varchar(20) NOT NULL,   `username` varchar(25) NOT NULL,   `study_group` varchar(6) default NULL,   `study_course` varchar(50) default NULL,   `card_code` varchar(15) default NULL,   `day_time` tinyint(1) default '0',   `email` varchar(100) default NULL,   `hashed_password` varchar(40) default NULL,   `salt` varchar(40) default NULL,   PRIMARY KEY  (`id`),   KEY `faculty` (`faculty_id`),   KEY `department` (`department_id`),   KEY `role` (`role_id`),   KEY `username` (`username`)  ) ENGINE=InnoDB DEFAULT CHARSET=utf8  1 row in set (0.02 sec)  mysql> 

adding user from the rails console

Loading development environment (Rails 3.0.3) irb(main):001:0> me = User.new => #<User id: nil, faculty_id: nil, department_id: nil, role_id: nil, name: "", surname: "", username: "", study_group: nil, study_cour se: nil, card_code: nil, day_time: false, email: nil, hashed_password: nil, salt: nil> irb(main):002:0> me.name = 'Daniel' => "Daniel" irb(main):003:0> me.surname = 'Garcia' => "Garcia" irb(main):004:0> me.username = 'vinagrito' => "vinagrito" irb(main):005:0> me.role_id = 1 => 1 irb(main):006:0> me.save => false irb(main):007:0> me.errors => {:password=>["is too short (minimum is 8 characters)"], :email=>["is invalid", "can't be blank"]} irb(main):008:0> me.password = '12345678' => "12345678" irb(main):009:0> me.email = 'mail@mail.com' => "mail@mail.com" irb(main):010:0> me.save => true irb(main):011:0> me => #<User id: 2, faculty_id: nil, department_id: nil, role_id: 1, name: "Daniel", surname: "Garcia", username: "vinagrito", study_group : nil, study_course: nil, card_code: nil, day_time: false, email: "mail@mail.com", hashed_password: "6305ee7016b263c0ec41a81439a378837a 318035", salt: "5c33e8fed10b87c9f4b7841f0faeb7b10424289a">    irb(main):013:0> user = User.where(:id => 2) => [#<User id: 2, faculty_id: nil, department_id: nil, role_id: 1, name: "Daniel", surname: "Garcia", username: "vinagrito", study_grou p: nil, study_course: nil, card_code: nil, day_time: false, email: "mail@mail.com", hashed_password: 6305.0, salt: "5c33e8fed10b87c9f4b 7841f0faeb7b10424289a">] 

See the "hashed_password" it returns to me

Output of the development.log

 [1m[36mSQL (1.0ms)[0m  [1mSHOW TABLES[0m  [1m[35mSQL (2.0ms)[0m  SHOW TABLES  [1m[36mSQL (1.0ms)[0m  [1mSELECT `schema_migrations`.`version` FROM  `schema_migrations`[0m  [1m[35mSQL (31.0ms)[0m  CREATE TABLE `users` (`id` int(11) DEFAULT  NULL auto_increment PRIMARY KEY, `faculty_id` int(11), `department_id`  int(11), `role_id` int(11) NOT NULL, `name` varchar(20) NOT NULL,  `surname` varchar(20) NOT NULL, `username` varchar(25) NOT NULL,  `study_group` varchar(6), `study_course` varchar(50), `card_code`  varchar(15), `day_time` tinyint(1) DEFAULT 0, `email` varchar(100),  `hashed_password` varchar(40), `salt` varchar(40)) ENGINE=InnoDB  [1m[36mSQL (68.0ms)[0m  [1mCREATE INDEX faculty ON   users(faculty_id)[0m   [1m[35mSQL (65.0ms)[0m  CREATE INDEX department ON  users(department_id)  [1m[36mSQL (78.0ms)[0m  [1mCREATE INDEX role ON users(role_id)[0m  [1m[35mSQL (80.8ms)[0m  CREATE INDEX username ON users(username)  [1m[36mSQL (30.0ms)[0m  [1mINSERT INTO `schema_migrations` (`version`)  VALUES ('20101226144503')[0m  [1m[35mSQL (7.0ms)[0m  SHOW TABLES  [1m[36mSQL (3.0ms)[0m  [1mSELECT `schema_migrations`.`version` FROM  `schema_migrations`[0m  [1m[35mSQL (2.0ms)[0m  SHOW TABLES  [1m[36mSQL (7.0ms)[0m  [1mdescribe `authors`[0m  [1m[35mSQL (2.0ms)[0m  SHOW KEYS FROM `authors`  [1m[36mSQL (7.0ms)[0m  [1mdescribe `book_loans`[0m  [1m[35mSQL (3.0ms)[0m  SHOW KEYS FROM `book_loans`  [1m[36mSQL (7.0ms)[0m  [1mdescribe `books`[0m  [1m[35mSQL (2.0ms)[0m  SHOW KEYS FROM `books`  [1m[36mSQL (7.0ms)[0m  [1mdescribe `departments`[0m  [1m[35mSQL (3.0ms)[0m  SHOW KEYS FROM `departments`  [1m[36mSQL (8.0ms)[0m  [1mdescribe `faculties`[0m  [1m[35mSQL (3.0ms)[0m  SHOW KEYS FROM `faculties`  [1m[36mSQL (7.0ms)[0m  [1mdescribe `roles`[0m  [1m[35mSQL (2.0ms)[0m  SHOW KEYS FROM `roles`  [1m[36mSQL (7.0ms)[0m  [1mdescribe `subjects`[0m  [1m[35mSQL (2.0ms)[0m  SHOW KEYS FROM `subjects`  [1m[36mSQL (7.0ms)[0m  [1mdescribe `users`[0m  [1m[35mSQL (1.0ms)[0m  SHOW KEYS FROM `users`  [1m[36mSQL (0.0ms)[0m  [1mSHOW TABLES[0m  [1m[35mSQL (0.0ms)[0m  BEGIN  [1m[36mSQL (0.0ms)[0m  [1mdescribe `users`[0m  [1m[35mAREL (0.0ms)[0m  INSERT INTO `users` (`faculty_id`,  `department_id`, `role_id`, `name`, `surname`, `username`,  `study_group`, `study_course`, `card_code`, `day_time`, `email`,  `hashed_password`, `salt`) VALUES (NULL, NULL, 1, 'Daniel', 'Garcia',  'viangrito', NULL, NULL, NULL, 0, 'mail@mail.com',  'e1382ac8675daee167a262ee7ef3bd038f997c4a',  'a3518e0a6b273590073bd733e2ee692fbca28c2d')  [1m[36mSQL (15.6ms)[0m  [1mCOMMIT[0m 
        
         
         

回答列表

1
 
vote
vote
最佳答案
 

所以最后经过几天的挣扎,昨天我发现了

https://github.com/brianmario/mysql2/issues.iseue/71 < / a>

被发现试图找到具有类似问题的别人 我不知道它是如何用于其他Windows用户,但我的架构是如何才能显示我的架构:

  (urlencode($[^][]*['Title']),ENT_QUOTES,s*'utf-8'); 1  

所以我下载了mysql 5.1。来自 http://dev.mysql.com/downloads/mysql/5.1.html现在一切都应该像它一样工作。 不是它显示了我的数据库的完整架构以及从中检索数据时不再被损坏

 

So finally after a couple of days of struggling, yesterday I found

https://github.com/brianmario/mysql2/issues#issue/71

Which was found trying to locate someone else with similar problems I don't know how it was for other windows users but my schema.rb was showing me no schema at all just:

  ActiveRecord::Schema.define(:version => XXXXXXXXXXXXXX) do #my last migration version       #Could not dump table "table_name" beacuse of following ArgumentError      #     invalid date      .      .      .# and so one for each table I had    end 

So I downloaded mysql 5.1. from http://dev.mysql.com/downloads/mysql/5.1.html and now everything's working like it should. Not it shows the full schema of my db and when retrieving data from it no longer gets corrupted

 
 

相关问题

0  Meta_Search NomethodError在使用fields_or_fields结构查询时  ( Meta search nomethoderror when using fields or fields structure query ) 
我正在使用meta_search。以下提供正确的结果: User.search({:first_name_contains_any => ["peter", "john"]}).all User.search({:last_name_contains_any => ["wong", "lee"]}).all ...

15  RSPEC,CONSAN,Validate_Uniqueity_Of,具有范围和错误消息  ( Rspec shoulda validate uniqueness of with scope and wrong error message ) 
我遵循rspec测试: describe Productlimit do before(:each) do @productlimit = Factory.create(:productlimit, :user => Factory.create(:user)) end subject ...

2  Controller#Action-Action的Nomethoderror - 未定义的方法`Keynote'#<User:0x007fba0e32f760>  ( Nomethoderror in controlleraction undefined method keynote for user0x007 ) 
我正在构建一个具有主题模型和故事模型的应用程序(以及我用设计实现的用户模型)。 keynotes有很多故事,故事属于主题演讲。 我遇到了创建新故事的问题,我收到以下错误: nomethoderror在storiescontroller#创建 未定义的方法`keynote'#user:0x007fba0e32f...

2  Rails 3路线和模块  ( Rails 3 routes and modules ) 
我在模块内有一个模型 class Long::Module::Path::Model < ActiveRecord::Base end 并希望使用以下路由(没有模块名称,因为它更容易写入和记住) resources :models 但是Rails 3总是希望使用像这样的URL long_mod...

3  使用大型数据集和Ruby  ( Working with large data sets and ruby ) 
可以真正在这里使用一些帮助。用大数据显示仪表板挣扎。 使用@ 2k记录平均值@ 2秒。 MySQL控制台中的查询需要少于3.5秒才能返回150k行。 Ruby中的相同查询需要4 +几分钟,直到所有对象都执行,并准备好。 目标:在添加缓存服务器之前,甚至进一步优化数据。使用Ruby 1.9.2,Rails 3.0和...

38  如何在轨道上生成真实的  ( How to generate authenticitytoken on rails ) 
我由自己构建表单标记,当我将表单发布到服务器时,它给我一个 InvalidAuthenticityToken 错误,所以我想知道如何在我自己的情况下添加它: <form accept-charset="UTF-8" action="/crops/update" method="post"> <input id...

0  Ubuntu - Apache - Rails - 乘客 - 产卵错误  ( Ubuntu apache rails passenger spawning error ) 
我有乘客抱怨的错误: *** Passenger ERROR (ext/common/ApplicationPool/../SpawnManager.h:220): Could not start the spawn server: /usr/local/rvm/gems/ruby-1.9.3-head/ruby...

1  使用Rails3同时插入多行  ( Inserting multiple rows simultaneously with rails3 ) 
我们有一个现有的MySQL数据库和PHP前端,我们目前正在使用DataMapper移植到ROR3应用程序。 我们需要用单个提交插入多行,每个行都使用相同的名称。例如,如果我查看组表,我们有这个结构: +-----------+------------------+------+-----+---------+--...

12  Rails 3,RSPEC 2.5:使用COUST_RECEIVE或Stub_CHAIN与命名范围  ( Rails 3 rspec 2 5 using should receive or stub chain with named scopes ) 
我使用Rails 3.0.4和RSPEC 2.5。在我的控制器中,我使用命名范围的重大,例如 @collection = guestbookentry.nonreplies.bydate.inclusive.paginate( :Page =&gt; Params [:Page],:条件=&gt...

7  Rails 3 / Bundler Gem:'未定义的方法`Setup'for Bundler:Module(Nomethoderror)'  ( Rails 3 bundler gem undefined method setup for bundlermodule nomethoderr ) 
可以追溯到配置/ boot.rb,第7行: require 'rubygems' require 'bundler' Bundler.setup 这是带有Bundler 0.8.1所谓的安装: ../Users/ashley$ sudo gem install bundler Successfully ...

7  Rails - Seeding Habtm协会  ( Rails seeding habtm associations ) 
Equipment.create(name: "Room to run") Equipment.create(name: "Pull-up bar") Workout.create( description: "Do 100 pull-ups then run 5km", :equipment => Eq...

0  使用Rails 3 View继承,是否可以在子视图中调用“超级”,但发送父变量?  ( With rails 3 view inheritance is it possible to call super within a child vie ) 
每个 show 在我的应用程序中的操作对每个模型具有相同的模板(它是一个admin-portal类型界面)。我有一个view show.html.erb 所有这些模型继承了。 控制器所有使用inheritedresources,因此我可以访问一些帮助程序变量,例如 99887662 ,我用来显示通过 998876...

0  两个控制器,一个布局,轨道3  ( Two controllers in one layout rails 3 ) 
好吧,我有两个型号,配方模型和类别模型。在我的布局(application.html.erb)中,我有一个主要的容器div,"收益" 的食谱索引动作。我试图通过在无序列表中迭代它们来将所有类别名称列为侧栏(也是div)中的链接。单击其中一个链接时,它将转到类别显示页面,然后将列出该类别中的所有配方。 这是我如何尝试...

1  如何在Rails中删除多个选中的记录?  ( How to delete multiple checked records in rails ) 
我想出了如何为每行显示复选框。 问题是我找不到如何编写form_tag和提交标记,以便使用et detele动作将已选中的行参数传递给messages_controller。 在删除操作中写的是什么。 请帮帮我! 我的观点是 Niki::class1 和控制器应该是这样的东西(根据此处 https://git...

3  独立的Rails应用每种型号/服务。  ( Standalone rails application per model service ) 
我刚刚在Hackernews上阅读了本文趋势 http://news.ycombinator.com/item?id=3199907 < / p> 我一直在考虑这一段时间,而在轨道中理解ActiveSesource之后。 http://reailscasts.com/episodes/94-attivere...

0  初始化安装的Rails 3插件宝石  ( Initialize a rails 3 plugin gem on installation ) 
我正在创建一个rubygem,我想知道是否有任何方法我可以设置它,以便在 RadioGroup3 中列出它,有人运行 RadioGroup4 ,我的宝石可以将一些文件复制到Rails路径中。这将保存用户必须键入 RadioGroup5 ,其中 RadioGroup6 是我宝石中的发电机的名称。 是否有一个回调,即在...

0  在Rails 3中加入一对多协会与许多多对多协会  ( Joining a one to many association with a many to many association in rails 3 ) 
我在用户类和表类之间有多对多关联。此外,我在用户和表格之间有一对多关联(一个用户最终拥有该表)。我正在尝试访问用户可以访问的所有表(基本上加入两个关联)。 另外,使用named_scope(现在的范围)是很好的。 这是我到目前为止的内容: class User < ActiveRecord::Base act...

6  Rails Active Admin资源问题  ( Rails active admin resource problem ) 
我最近观看了关于Active Admin的RailScast 284,并希望将其实施到我的Web应用程序中,但是当我添加资源时,我正在运行到一个问题中。每次尝试导航到创建的选项卡时,我会收到以下消息: NameError in Admin::LoadsController#index undefined loc...

1  Rails 3 - Helper,他们应该被使用在哪里?  ( Rails 3 helper where are they supposed to be used ) 
我正在构建一个模型,只要模型运行,我想注入新闻饲料模型。我的想法是在模型中创建一个ander_save,然后使用帮助程序来填充饲料细节。但我的模型没有找到助手...... 现在我想知道,有什么帮助者,是助手真正只是看见或? 在我的模型中,我想运行类似的东西: newsfeed.feeded_id = Rec...

238  rmagick gem安装“找不到magick-config”  ( Rmagick gem install cant find magick config ) 
我在尝试安装rmagick gem时得到下面显示的错误。我在Snowleopard 10.6上使用RVM,Ruby 1.9.2-Head和Rails 3.05。对类似问题的回应推荐安装ImageMagick,我成功地完成了。其他建议安装"libmagick9-dev库" ,但是,我无法弄清楚如何执行此操作。 我是一个...

6  Rails 3:Google Apps / Heroku的SMTP设置  ( Rails 3 smtp settings for google apps heroku ) 
以下是setup_mail.rb中Google Apps的SMTP设置。 :address => "smtp.gmail.com", :port => 587, :domain ...

2  尝试访问Join Table Rails中的属性  ( Trying to access attribute in join table rails ) 
好的我认为我有两个需要修复的问题 我有以下表格: Student , Register Register Register 和一个连接表,它显示1 register有许多学生的记录,称为"regisers_students" ,看起来像这样:. 我必须通过 rails g migration CreateS...

1  Rails文件转换建议  ( Rails document conversion suggestion ) 
嗨,我目前正在学习轨道,日常我得到更多附加。我想使用Rails构建一个具有类似功能的Web应用程序,如 http://www.scribd.com/或Docstoc。 Rails或Ruby中的组件/ Gems /插件/库可用于创建具有类似功能的Web应用程序。 Web应用程序应该具有 EPUB焦康酸升及图像(JP...

0  @ user.visit_count =>未定义的方法  ( User visit count undefined method ) 
我正在做我想的是非常简单的东西 - 找到一个用户并递增整数。 recording.wav6 我收到以下错误: recording.wav7 这似乎是一个轨道3件事 - 我在哪里出错了? ...

8  Rails ActiveRecord查询比较同一记录的两个属性  ( Rails activerecord query comparing two attributes of same record ) 
我正在寻找一种建立查询的方法,该查询比较相同记录的两个属性,而无需首先拔出记录并进行比较后查询。我的具体情况可能有10k的记录,因此迭代通过每个都不是一个选项。 示例:通过查询updated_at == created_at 来查找此记录 #<User id: 1, name: "xxx", created_at...




© 2021 it.wenda123.org All Rights Reserved. 问答之家 版权所有