moving from sqlite3 to mysql

289 views
Skip to first unread message

Malik Rumi

unread,
Jan 28, 2014, 12:17:32 PM1/28/14
to django...@googlegroups.com
This is somewhat like the question in "need help moving to production server" but I think the right procedure is to start a new thread. So I think I have done well for just starting out. With your help I've gotten Django running on Windows, and I completed a tutorial and got my site working locally with the admin. thank you.

So I thought I was ready to move up to MySQL for some heavy lifting. I followed the instructions I got here http://matthewwittering.com/blog/how-to-migrating-the-database-engine-for-django.html. I did not know what to do with the NAME part, so I put in 'django-1', and promptly got the error message 'unknown database 'django-1'. I thought that made sense because I hadn’t created this database in mysql already, but I was just blindly following along. Having to CREATE DATABASE doesn’t make sense, I thought, because it defeats the purpose of Django abstraction in the first place. Besides, when I syncdb, it should take whatever name I gave it when I was using sqlite3, right?

Wrong. When I ran syncdb, this time with NAME: ' ', I got :   File "C:\Python27\lib\site-packages\MySQLdb\connections.py", line 36, in default terror handler    raise errorclass, errorvalue django.db.utils.OperationalError: (1046, 'No database selected').

So, what am I missing here? There almost certainly is an easy solution I'm not seeing. Do I need to create a database in mysql? If so, must it have the same name as it had in sqlite3? I know that name was made from putting the model name together with something else, but I don't actually remember what it was, and it seems like a lot of extra work to install an sqlite browser just to get that name right. If that's what I need to do, maybe I can just open that file with notepad? 

Or can I create the database, (presumably directly in the shell), and then empty it, as these instructions say, and that will take care of it? I frankly didn't understand why I would need to 'empty' a new and empty database, but that's what it says. 

Any and all helpful advise welcome and appreciated. 

donarb

unread,
Jan 28, 2014, 12:31:01 PM1/28/14
to django...@googlegroups.com
You should go through the tutorial, which explains how to create a project.

From the database setup page:

"If you’re using PostgreSQL or MySQL, make sure you’ve created a database by this point. Do that with “CREATE DATABASE database_name;” within your database’s interactive prompt.

If you’re using SQLite, you don’t need to create anything beforehand - the database file will be created automatically when it is needed." 



Daniel Roseman

unread,
Jan 28, 2014, 6:50:24 PM1/28/14
to django...@googlegroups.com
You're confusing databases with tables.
Django will create the tables for you, but they need a database to go in
You need to create that yourself with the simple CREATE DATABASE command in mysql.
--
DR.

Ariel E. Isidro

unread,
Jan 28, 2014, 9:45:27 PM1/28/14
to django...@googlegroups.com
"Or can I create the database, (presumably directly in the shell), and then empty it, as these instructions say, and that will take care of it? I frankly didn't understand why I would need to 'empty' a new and empty database, but that's what it says. "

With sql lite, everything will be created for you.
While with MySQL,  you should create the database directly in the shell, and this should give you an empty database.  The Django tables will be created after configuring your settings, and running  syncdb.




--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/f4a6d446-7cf8-498a-8ba5-04e339dd80b9%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.



--

DISCLAIMER: This message is for the designated recipient only and may contain confidential and/or privileged information. If you have received it in error, please delete it and advise the sender immediately. You should not copy or use it for any other purpose, nor disclose its contents to any other person.

Malik Rumi

unread,
Feb 5, 2014, 5:38:59 PM2/5/14
to django...@googlegroups.com

mysql>  CREATE DATABASE django_1;

Query OK, 1 row affected (0.24 sec)

mysql> SHOW DATABASES;

+--------------------+

| Database           |

+--------------------+

| information_schema |

| django_1           |

| mysql              |

| performance_schema |

| test               |

+--------------------+

5 rows in set (0.31 sec)

mysql> exit

Bye

python manage.py syncdb

Traceback (most recent call last):

(…)

File "C:\Python27\lib\site-packages\MySQLdb\connections.py", line 36, in defaulterrorhandler    raise errorclass, errorvalue

django.db.utils.OperationalError: (1046, 'No database selected')

python manage.py syncdb django_1

CommandError: Command doesn't accept any arguments

python manage.py syncdb --django_1

Usage: manage.py syncdb [options]

Create the database tables for all apps in INSTALLED_APPS whose tables haven't already been created.

manage.py: error: no such option: --django_1

<>

Ok, so MySQL wanted a db name, even though there was no db name (at least not one I gave it) on sqlite3

when I ran syncdb without a name, it said no db selected

When I tried pointing it to a name, I got 'doesn't accept arguments' and then 'no such option.'

Is django now saying this new database has to be listed as an installed app? What am I missing here?

 - and thanks for much for your help.



--
You received this message because you are subscribed to a topic in the Google Groups "Django users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/django-users/zpNqaA2Fji8/unsubscribe.
To unsubscribe from this group and all its topics, send an email to django-users...@googlegroups.com.

To post to this group, send email to django...@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.

Drew Ferguson

unread,
Feb 5, 2014, 6:52:35 PM2/5/14
to django...@googlegroups.com
Hi

Just like SQLlite, you tell Django where the MySQL database is in
settings.py

At the top you should have something like

DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'django_1', # Or path to database file if using sqlite3.
# 'USER': '',
# 'PASSWORD': '',
# 'HOST': '', # Empty for localhost
# 'PORT': '', # Set to empty string for default.
}
}


On Wed, 5 Feb 2014 16:38:59 -0600
Malik Rumi <malik....@gmail.com> wrote:

> mysql> CREATE DATABASE django_1;
>
> Query OK, 1 row affected (0.24 sec)
>
> mysql> SHOW DATABASES;
>
> +--------------------+
>
> | Database |
>
> +--------------------+
>
> | information_schema |
>
> | django_1 |
>
> | mysql |
>
> | performance_schema |
>
> | test |
>
> +--------------------+
>
> 5 rows in set (0.31 sec)
--
Drew Ferguson
AFC Commercial
http://www.afccommercial.co.uk

Ariel E. Isidro

unread,
Feb 5, 2014, 8:44:02 PM2/5/14
to django...@googlegroups.com
1. before exiting mysql, you should grant permission to a user,i.e.
grant all privileges on django_1.* to username@'localhost' identified by 'userpassword'
replace username, userpassword with your own
2. exit mysql console
3. modify settings.py to add your username, password, host (localhost), and port (3306)
4. run python manage.py syncdb


--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.

Malik Rumi

unread,
Feb 6, 2014, 11:33:32 AM2/6/14
to django...@googlegroups.com
Ok, I got it working. And by working, I mean I got it to sync, I imported the database.json into mysql, and when I runserver everything is there as it should be. 
So, many thanks to all my gracious and more senior django users for your patient guidance and assistance. 
A note to all newbies who may be following along and reading this days, weeks, and years from now: Do yourself a favor and READ the documentation, DON'T just scan it looking for a quick answer. You are bound to miss something important. 
Turns out that for all my struggling with a db name for mysql, all that came after I had changed the settings.py to mysql. In other words, I didn't think to go back and put the name I came up with, django_1, in settings.py. But that was not enough. Now I had to also take off the '--database=django_1' as that was unnecessary and maybe confusing django. Once I did that, it all worked. 

But don't worry, I'm sure I'll be back soon enough with some other issues..... :-)


--
You received this message because you are subscribed to a topic in the Google Groups "Django users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/django-users/zpNqaA2Fji8/unsubscribe.
To unsubscribe from this group and all its topics, send an email to django-users...@googlegroups.com.

To post to this group, send email to django...@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
Reply all
Reply to author
Forward
0 new messages