Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Connecting to MySQL from Django

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??

like image 732
gunj Avatar asked Dec 09 '22 11:12

gunj


2 Answers

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.

like image 167
Joe Avatar answered Dec 12 '22 00:12

Joe


  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.

like image 33
panchicore Avatar answered Dec 11 '22 23:12

panchicore