4

its my first project with django..i already tried the connection with sqlite.but now m using django's connection with mysql n m getting following error...

D:\project\wogma>manage.py syncdb Traceback (most recent call last): File "D:\project\wogma\manage.py", line 11, in <module> execute_manager(settings) File "C:\Python26\lib\site-packages\django\core\management\__init__.py", line 340, in execute_manager utility.execute() File "C:\Python26\lib\site-packages\django\core\management\__init__.py", line 295, in execute self.fetch_command(subcommand).run_from_argv(self.argv) File "C:\Python26\lib\site-packages\django\core\management\base.py", line 192, in run_from_argv self.execute(*args, **options.__dict__) File "C:\Python26\lib\site-packages\django\core\management\base.py", line 218, in execute self.validate() File "C:\Python26\lib\site-packages\django\core\management\base.py", line 246, in validate num_errors = get_validation_errors(s, app) File "C:\Python26\lib\site-packages\django\core\management\validation.py", lin e 65, in get_validation_errors connection.validation.validate_field(e, opts, f) File "C:\Python26\lib\site-packages\django\db\backends\mysql\validation.py", l ine 8, in validate_field db_version = connection.get_server_version() File "C:\Python26\lib\site-packages\django\db\backends\mysql\base.py", line 27 7, in get_server_version self.cursor() File "C:\Python26\lib\site-packages\django\db\backends\__init__.py", line 56, in cursor cursor = self._cursor(settings) File "C:\Python26\lib\site-packages\django\db\backends\mysql\base.py", line 26 2, in _cursor self.connection = Database.connect(**kwargs) File "C:\Python26\lib\site-packages\MySQLdb\__init__.py", line 81, in Connect return Connection(*args, **kwargs) File "C:\Python26\lib\site-packages\MySQLdb\connections.py", line 188, in __in it__ super(Connection, self).__init__(*args, **kwargs2) _mysql_exceptions.OperationalError: (1049, "Unknown database 'd:/project/wogma/w ogma'") 

i did the commands in mysql as follows..i already created the wogma database just using create database n i granted the priviliges..in mysql. whts the prb??

4 Answers 4

7

You are trying to specify a database at a file path (which would work for SQLite). MySQL needs a database name (e.g. 'wogma'). You'll have to follow the instructions to install MySQL, create a new user and database etc. It appears you're on Windows, so I can't help any more than that.

Sign up to request clarification or add additional context in comments.

1 Comment

@gunj: Please fix the shift-lock key on your keyboard.
4
  1. open a sql console and type SHOW DATABASES;
  2. if wogma appear just put this in your settings (you are using django 1.1):

    DATABASE_ENGINE = 'django.db.backends.mysql'

    DATABASE_NAME = 'wogma'

    DATABASE_HOST = '127.0.0.1'

    DATABASE_PORT = '3306'

  3. if not appear just create it in this console CREATE DATABASE wogma ; and make the steps again.

Comments

3

Try with this connection configuration:

DATABASES = { 'default': { 'ENGINE': 'django.db.backends.mysql', 'NAME': 'MY_DATABASE_NAME', 'USER': 'root', 'PASSWORD': 'MY_PASSWORD', } } 

But First, create the database in your mysql.

Comments

0

As directed by above answers , the below code will not work

 DATABASES = { 'default': { 'ENGINE': 'django.db.backends.mysql', 'NAME': 'MY_DATABASE_NAME', 'USER': 'root', 'PASSWORD': 'MY_PASSWORD', } } 

You would have to download MySQL Connector. Read this post to setup your MySQL database in Django 2.1.x

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.