Python, MySQL, Django, Syncdb gives DataBaseError (1046, No database selected) - python

I have installed mysql, added it to services to start automatically, however when i try to run the command line interface it says that it cannot find mysql.exe. It asks me to browse for it. I am using windows 10 64 bit and mysql Cluster 7.4. I am following instructions and all they say to do is just enter the instruction to the command line like this manage.py syncdb and that is all that is said on the matter. Thanks in advance for any help that i get.

Have you defined your database in settings.py
https://docs.djangoproject.com/en/1.9/ref/settings/#databases
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'mydatabase',
'USER': 'mydatabaseuser',
'PASSWORD': 'mypassword',
'HOST': '127.0.0.1',
'PORT': '5432',
}
}
where engine is your database engine.

Related

Error while switching the database from sqllite to postgre django

I changed the values of the DATABASE variable in the file settings.py to
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql',
'NAME': 'postgres',
'USER': 'postgres',
'PASSWORD': 'password',
'HOST': 'localhost',
'PORT': "5432"
}
}
but now after i run python manage.py migrate i'm getting the error
django.db.utils.ProgrammingError: column "name" of relation "django_content_type" does not exist
can someone tell what this error means and how to fix it
I figured it out. This occurred because i had to databases sharing the same name. If you came across the same error check that

getting ConnectionDoesNotExist error when attempting to migrate mysql database in django

here's my code in django settings.py for the database:
DATABASES= {
'defualt': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'cameronkc',
'USER': 'root',
'PASSWORD': '123456',
'HOST': 'localhost',
'PORT': ''
}
}
here's the error im recieving when executing >python manage.py migrate in command prompt
django.db.utils.ConnectionDoesNotExist: The connection default doesn't exist
You misspelled default in your DATABASES dict. Change 'defualt' to 'default'.

Django Database Migration

Hi have a django project a full project now I want to migrate to mysql from the default Sqlite3 which is the default database. I am on a Mac OS and I don't know how to achieve this process. Any one with a complete guide on how to make the switch would be appreciated.
Go to your project's settings file and edit DATABASES with proper database connection
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'DB_NAME',
'USER': 'DB_USER',
'PASSWORD': 'DB_PASSWORD',
'HOST': 'localhost',
'PORT': '3306',
}
}
Now open mysql and create database as you give in DATABASE settings.
Go to your project -
./manage makemigrations
./manage migrate
This will create all the tables in the specified database name.

Django migrate tables to new database

I originally had a django project with a single app and all models were defined in that app. The project, when initiated only used the default database. It has now become an unwieldy app that I'm trying to break down into smaller apps. Doing so, I want to use different databases for the different apps. I've setup new databases and a router in the settings.py file. However, I'm confused about how to migrate existing tables to the new databases.
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'db_name',
'USER': 'db_user_name',
'PASSWORD': 'password',
'HOST': 'hostname',
'PORT': '3306',
},
'db2': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'db_name2',
'USER': 'db_user_name2',
'PASSWORD': 'password2',
'HOST': 'hostname2',
'PORT': '3306',
}
}
I would want an app (e.g. app1) to be moved from default to db2. The router already knows to specify app1 to db2 but running migrations is doing nothing. Any ideas?
#knbk's answer was ultimately correct, except that the solution involved an additional step.
1. python manage.py migrate auth --database=db2
2. python manage.py migrate app1 --database=db2

django mysql gives page not found (404) while sqlite works fine

I have two settings files for my django project with different database settings.
First:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'dbname',
'USER': 'user',
'PASSWORD': 'megahardbreakingpassword',
'HOST': 'localhost',
'PORT': '',
'OPTIONS': {
'init_command': 'SET storage_engine=INNODB',
}
}
}
And second:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': 'db.sqlite3',
'USER': '',
'PASSWORD': '',
'HOST': '',
'PORT': '',
}
}
When I run server with second database settings project works fine, but when I run first settings file with mysql, django returns 404 error for all urls.
I also use django-hosts for implementing subdomains patterns, so maybe something wrong here. My hosts.py code:
from django_hosts import patterns, host
host_patterns = patterns('',
host(r'^$', 'project.urls', name='host'),
)
I use django 1.4.2 and Python 2.7.9
And finally I found answer! According to e4c5's comment I searched problem in my views instead of my settings files. I wrote simple unittest and it gives me some strange tracebeck about my MySQL database such as wrong column name and deprecation warnings about duplication indexes.
I reinstall older version of MySQL server (5.0.70 instead of 5.6.25), run syncdb and migrations again and it completely solved my problems. So God bless TDD!

Categories

Resources