# Sqlite to mysql

**URL:** <https://www.ruby-forum.com/t/sqlite-to-mysql/182789>\
**Category:** Rails\
**Created:** [February 2, 2010, 8:36pm UTC](https://www.ruby-forum.com/t/sqlite-to-mysql/182789 "2010-02-02T20:36:45Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![bluegreen](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/8491ac/32.png) [@bluegreen](https://www.ruby-forum.com/u/bluegreen)\
**Post date:** [February 2, 2010, 8:36pm UTC](https://www.ruby-forum.com/t/sqlite-to-mysql/182789/1 "2010-02-02T20:36:45Z")

</div>

Hi, there. I have an application running with sqlite in development mode  
and production mode. I just installed mysql on windows and created a  
new database in mysql for the application in development mode. After  
putting some data in database, I found that I can’t save Time object  
like 'Tue Feb 01 12:34:56 UTC 2000" completely. Mysql showed the time  
only “12:34:26”. But sqlite is able to save it and convert it to  
something like “2010-02-01 12:34:56”. I had to convert the Time object  
before I saved it to database.  
The other problem I encountered is storing long string in mysql. I put  
some long strings(about thousand characters) in one of the columns in a  
table using sqlite without any problems. When I did it with mysql, it  
truncated the string by itself with less than 300 characters left. It  
did that on every long string in the table. I did not change any ruby  
code except the yml file. Did I miss something?  
Thanks in advance.

---

<div class="post-metadata">

**Author:** ![bluegreen](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/8491ac/32.png) [@bluegreen](https://www.ruby-forum.com/u/bluegreen)\
**Post date:** [February 2, 2010, 10:12pm UTC](https://www.ruby-forum.com/t/sqlite-to-mysql/182789/2 "2010-02-02T22:12:34Z")

</div>

On Tue, Feb 2, 2010 at 11:36 AM, Ichiro S. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> Hi, there. I have an application running with sqlite in development mode  
> and production mode. I just installed mysql on windows and created a  
> new database in mysql for the application in development mode.

> Did I miss something?

Your MySQL field definitions obviously don’t match the data you’re  
trying to store there.

Did you create it by hand or using rake and migrations/schema load?

–  
Hassan S. ------------------------ removed\_email\_address@domain.invalid  
twitter: @hassan

---

<div class="post-metadata">

**Author:** ![bluegreen](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/8491ac/32.png) [@bluegreen](https://www.ruby-forum.com/u/bluegreen)\
**Post date:** [February 2, 2010, 11:08pm UTC](https://www.ruby-forum.com/t/sqlite-to-mysql/182789/3 "2010-02-02T23:08:25Z")

</div>

Hassan S. wrote:

> On Tue, Feb 2, 2010 at 11:36 AM, Ichiro S. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
> wrote:
> 
> > Hi, there. I have an application running with sqlite in development mode  
> > and production mode. ï¿½I just installed mysql on windows and created a  
> > new database in mysql for the application in development mode.
> 
> > Did I miss something?
> 
> Your MySQL field definitions obviously don’t match the data you’re  
> trying to store there.
> 
> Did you create it by hand or using rake and migrations/schema load?
> 
> –  
> Hassan S. ------------------------ removed\_email\_address@domain.invalid  
> twitter: @hassan  
> Hi, Hassan.  
> I ran:  
> rake db:create  
> rake db:migrate  
> also tried:  
> rake db:create  
> rake db:schema:load  
> both have the same problem mentioned in the previous post.

---

<div class="post-metadata">

**Author:** ![bluegreen](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/8491ac/32.png) [@bluegreen](https://www.ruby-forum.com/u/bluegreen)\
**Post date:** [February 2, 2010, 11:21pm UTC](https://www.ruby-forum.com/t/sqlite-to-mysql/182789/4 "2010-02-02T23:21:09Z")

</div>

On Tue, Feb 2, 2010 at 2:08 PM, Ichiro S. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> > Your MySQL field definitions obviously don’t match the data you’re  
> > trying to store there.

> both have the same problem mentioned in the previous post.

Somewhat surprising, but still – if it’s wrong, it’s wrong. What does  
`show create table` say about the fields that are failing for specific  
inputs?

–  
Hassan S. ------------------------ removed\_email\_address@domain.invalid  
twitter: @hassan

---

<div class="post-metadata">

**Author:** ![bluegreen](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/8491ac/32.png) [@bluegreen](https://www.ruby-forum.com/u/bluegreen)\
**Post date:** [February 2, 2010, 11:43pm UTC](https://www.ruby-forum.com/t/sqlite-to-mysql/182789/5 "2010-02-02T23:43:34Z")

</div>

Hassan S. wrote:

> On Tue, Feb 2, 2010 at 2:08 PM, Ichiro S. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
> wrote:
> 
> > > Your MySQL field definitions obviously don’t match the data you’re  
> > > trying to store there.
> 
> > both have the same problem mentioned in the previous post.
> 
> Somewhat surprising, but still – if it’s wrong, it’s wrong. What does  
> `show create table` say about the fields that are failing for specific  
> inputs?
> 
> –  
> Hassan S. ------------------------ removed\_email\_address@domain.invalid  
> twitter: @hassan

under Type, it’s “varchar(255)”

---

<div class="post-metadata">

**Author:** ![bluegreen](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/8491ac/32.png) [@bluegreen](https://www.ruby-forum.com/u/bluegreen)\
**Post date:** [February 3, 2010, 12:02am UTC](https://www.ruby-forum.com/t/sqlite-to-mysql/182789/6 "2010-02-03T00:02:05Z")

</div>

Hassan S. wrote:

> On Tue, Feb 2, 2010 at 2:43 PM, Ichiro S. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
> wrote:
> 
> > under Type, it’s “varchar(255)”
> 
> So if you want to store more than 255 characters, as you indicated  
> earlier, you need to change that field 🙂
> 
> Not too surprising, eh?
> 
> –  
> Hassan S. ------------------------ removed\_email\_address@domain.invalid  
> twitter: @hassan

Oh. How can I change that field?  
When I checked the same field in sqlite3, it is also “varchar(255)”.  
Could you please explain it a little more?

---

<div class="post-metadata">

**Author:** ![bluegreen](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/8491ac/32.png) [@bluegreen](https://www.ruby-forum.com/u/bluegreen)\
**Post date:** [February 2, 2010, 11:50pm UTC](https://www.ruby-forum.com/t/sqlite-to-mysql/182789/7 "2010-02-02T23:50:26Z")

</div>

On Tue, Feb 2, 2010 at 2:43 PM, Ichiro S. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> under Type, it’s “varchar(255)”

So if you want to store more than 255 characters, as you indicated  
earlier, you need to change that field 🙂

Not too surprising, eh?

–  
Hassan S. ------------------------ removed\_email\_address@domain.invalid  
twitter: @hassan

---

<div class="post-metadata">

**Author:** ![bluegreen](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/8491ac/32.png) [@bluegreen](https://www.ruby-forum.com/u/bluegreen)\
**Post date:** [February 3, 2010, 12:44am UTC](https://www.ruby-forum.com/t/sqlite-to-mysql/182789/8 "2010-02-03T00:44:41Z")

</div>

Ichiro S. wrote:

> Hassan S. wrote:
> 
> > On Tue, Feb 2, 2010 at 2:43 PM, Ichiro S. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
> > wrote:
> > 
> > > under Type, it’s “varchar(255)”
> > 
> > So if you want to store more than 255 characters, as you indicated  
> > earlier, you need to change that field 🙂
> > 
> > Not too surprising, eh?
> > 
> > –  
> > Hassan S. ------------------------ removed\_email\_address@domain.invalid  
> > twitter: @hassan
> 
> Oh. How can I change that field?  
> When I checked the same field in sqlite3, it is also “varchar(255)”.  
> Could you please explain it a little more?

It works! Thanks Hassan. But still not sure why sqlite3 has  
“varchar(255)” as well. Maybe that’s not the real length of the field.

---

<div class="post-metadata">

**Author:** ![bluegreen](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/8491ac/32.png) [@bluegreen](https://www.ruby-forum.com/u/bluegreen)\
**Post date:** [February 3, 2010, 12:50am UTC](https://www.ruby-forum.com/t/sqlite-to-mysql/182789/9 "2010-02-03T00:50:07Z")

</div>

On Tue, Feb 2, 2010 at 3:44 PM, Ichiro S. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> It works! Thanks Hassan. But still not sure why sqlite3 has  
> “varchar(255)” as well. Maybe that’s not the real length of the field.

Apparently that’s just a serving suggestion in SQLite3 – it doesn’t  
even issue a warning; MySQL does 🙂

–  
Hassan S. ------------------------ removed\_email\_address@domain.invalid  
twitter: @hassan
