Set up a Django Project with Mamp? - python

I just downloaded a newer version of MAMP (3.2.1) and i noticed that this Version has Python installed and also seems to handle SQLite Databases.
Shouldn't I be able to manage Django Projects with it?
Where and how would i install it?
I found some Posts in the Web (before my new MAMP release) where People already trying to get MAMP + Django to work with MySQL but those seemed more complicated to me then the usual setup with Virtualenv + SQLite/Postgres.
I'm pretty new to django but starting a project at the time seems quite simple to me.
If Django would work with MAMP together what would be the advantages?
Anyone has already experiences or useful links?

OK i gues working with MAMP MySQL has the advantage that i can easy import/export Database with php MyAdmin tool.
Anyway based on tanorix answer here how for me Django worked with MAMP MySQL Database:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'projectdb',
'USER': 'root',
'PASSWORD': 'root',
'HOST': '/Applications/MAMP/tmp/mysql/mysql.sock',
'PORT': '8888',
}
}
Then
python manage.py migrate

I don't have knowledge about MAMP but I can give you some elements to put Django Database with WAMP, so I think it can be the same manipulation:
First, in MAMP, you need to create a database, call it : projectdb.
Then, at your settings.py, update your variable DATABASES like this:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql', # Add 'postgresql_psycopg2', 'mysql', 'sqlite3' or 'oracle'.
'NAME': 'projectdb', # Or path to database file if using sqlite3.
# The following settings are not used with sqlite3:
'USER': 'root',
'PASSWORD': '',
'HOST': '127.0.0.1', # Empty for localhost through domain sockets or '127.0.0.1' for localhost through TCP.
'PORT': '', # Set to empty string for default.
}
}
Then, if you are using South, at your shell write this:
python manage.py schemamigration <name of your app> --init
python manage.py syncdb # => create your tables at your MAMP
python manage.py migrate

Related

django.db.backends.postgresql error when try to makemigrations my django project

I am trying to switch my Django database from SQLite3 to PostgreSQl, so I follow many tutorials to install and setup Postgres with Django project.
I did the following: pip install psycopg2, pip install psycopg2-binary and I modified the settings.py like that:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql',
'NAME': BASE_DIR / 'db.postgresql',
'USER': 'muusername',
'PASSWORD': 'mypassword',
'HOST': '127.0.0.1',
'PORT': '5432'
}
}
Finally I maked my database, by running the command python manage.py makemigrations.
However, I got this error:
django.core.exceptions.ImproperlyConfigured: 'django.db.backends.postgresql' isn't an available database backend or couldn't be imported. Check the above exception. To use one of the built-in backends, use 'django.db.backends.XXX', where XXX is one of:
'mysql', 'oracle', 'sqlite3'
Please note that I am also seccesufully install the pgAdmin in my OS which is Windows 10 in a first step.
I know that the problem is related by configuration of Postgres in my django project, but I don't know how to fix it, also I checked my djnago version which is the latest one, also, all needed packages are installed in my venv.
You cannot add like this in postgres:
'NAME': BASE_DIR / 'db.postgresql', #You got that error because of this. This setting is for only sqlite3 not for postgres
Just add db_name in NAME:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql_psycopg2',
'NAME': 'your_db_name', #add your db name here
'USER': 'postgres',
'PASSWORD': 'your_db_password',
'HOST': '127.0.0.1',
'PORT': '5432',
}
}
Make sure you have actually downloaded the PostgreSQL installer itself and installed it.
I solve this problem by just upgrade the django, as you can see here in the exception:
django.core.exceptions.ImproperlyConfigured: 'django.db.backends.postgresql' isn't an available database backend or couldn't be imported. Check the above exception. To use one of the built-in backends, use 'django.db.backends.XXX', where XXX is one of:
'mysql', 'oracle', 'sqlite3'
Django ask the user to use mysql, oracle or sqlite3, but not the case of postgresql.
So this exception will be fixed when the user upgrade the django version.
I hope this answer can be helpful for someone another.

Django mysql connection errors

Try to connect my django project with MySQL using wamp server i am facing error
"Django.db.utils.NotsupportedError"
I am tried older version of django
To solve this error, but it seems also
Same error.
To connect Django to a MySQL database, you will need to install a MySQL database connector. The most common connector is mysql-connector-python, which you can install using pip:
pip install mysql-connector-python
Once the connector is installed, you will need to update your Django settings to use the connector and specify the connection parameters for your MySQL database. The settings will typically look like this:
DATABASES = {
'default': {
'ENGINE': 'mysql.connector.django',
'NAME': 'mydatabase',
'USER': 'myuser',
'PASSWORD': 'mypassword',
'HOST': '127.0.0.1',
'PORT': '3306',
}
}
You will need to replace the NAME, USER, PASSWORD, HOST, and PORT values with the appropriate values for your MySQL database.
Once you have configured your settings, you can run the migrate command to create the necessary database tables:
python manage.py migrate
This will create the tables in your MySQL database that are needed by Django. You should now be able to use your MySQL database with Django.

Following Django tutorial, "python manage.py migrate" doesn't create any django tables (MySQL, Pycharm)

In mysite.settings.py I have:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': os.path.join(BASE_DIR, 'test'),
#'NAME': 'test',
'USER': 'root',
'PASSWORD': 'password',
'HOST': 'localhost',
'PORT': '3306',
}}
When I run 'python manage.py migrate' in the PyCharm terminal, nothing happens, no error message etc. No new tables are created in the database specified. I tried two things for NAME as you can see.
MySQL Server version 8.0.19
MySQL Connector/Python 8.0.19
Python version 3.8
In PyCharm I have package mysqlclient 1.4.6 installed.
Any advice on how to find the problem? How to get an error message?
Thank you
DATABASES property specifies your DB configurations. Now NAME is the property which specifies your database name.
Currently here 'NAME': os.path.join(BASE_DIR, 'test'), won't work as it will give you something like C:/YourUser/YourPath... so this string is not a valid db name. basically (os.path.join() returns a path to your project directory)
First create a db manually on MySql, note the name and put it in property as 'Name': DBNAME in SETTINGS.py.
(Make sure you have your environment set while running following commands)
Then try python manage.py makemigrations for checking migration changes, if everything goes fine up till here then fire python manage.py migrate command.

Django won't make migrations with MySQL Database

I'm trying to make the migrations between my database (MySQL) and Django. I used the same parameters in Linux and didn't have any problems. Now I'm using the command :
python manage.py migrate
and I get nothing at all on the terminal. However, the command works if I let the default parameters ( for a sqlite database ). Also, I've noticed that it actually reads the 'settings.py' file because it returns an error if I write something that doesn't make any sense. Here are my parameters, I know for sure that they are correct ( I checked with the MySQL commands ).
settings.py
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'my_db',
'USER': 'root',
'PASSWORD': '123456789_dont_judge_me',
'HOST': '127.0.0.1',
'PORT': '3306',
}
}
Error message
I'm using Windows 10, Python 3.5 and Django 2.0.
Do you have any idea where the problem could come from ?
Thank you for your responses kind people !
You can try this.
Note: I am not claiming it is best solution, but it is working for me
in case of Window10.
Step1 : Install pymysql
pip install pymysql
Step2: Edit settings.py
settings.py
---------------
import os
import pymysql
pymysql.install_as_MySQLdb()
import MySQLdb
# Database
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'django_test',
'USER': 'root',
'PASSWORD': '123456',
'HOST': '127.0.0.1',
'PORT': '3306',
}
}
Step3: migrate it
python manage.py migrate
you can follow this link

Setting up Django with MySQL, syncdb giving segmentation fault?

I'm currently working on building a Django app. I'm following the "tangowithdjango" tutorial, which uses Django 1.54. In their tutorial, they use Sql-lite, but I'm planning on building this app for most robust purpose, which is why I'm attempting to connect MySQL instead.
Needless to say, it's been a nightmare. I can't get MySQL to connect for the life of me.
Here's what my settings.py looks like:
DATABASE_PATH = os.path.join(PROJECT_PATH, 'app.db')
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'rideb',
'USER': 'root',
'PASSWORD': 'nantucket',
#'HOST': 'localhost', # Empty for localhost through domain sockets or '127.0.0.1' for localhost through TCP.
#'PORT': '', # Set to empty string for default.
}
}
And here's my output I'm getting...
(rideb)grantmcgovern#gMAC:~/Dropbox/Developer/Projects/RideB/master$ python manage.py syncdb
Segmentation fault: 11
I've installed python-mysqldb, and now I'm simply getting this, and I'm very perplexed to say the least. Is it some Django compatibility issue?
Everything works fine as the tutorial suggests with SQL-lite, but not looking to use that.
OS:
Mac OSX 10.10 Yosemite
MySQL (installed via .dmg on Oracle's site):
Server version: 5.6.19 MySQL Community Server (GPL)
I had a similar problem and it turns out it was related to incorrect mysql implementation on my Mac (OS X 10.10 Yosemite). I had "mysql-connector-c" installed instead of "mysql". Uninstalling "mysql-connector-c" (brew uninstall mysql-connector-c) and installing "mysql" (brew install mysql) resolved the problem right away.
To find out if you are facing this exact problem as I did, open the Console app on your Mac, go to User Diagnostic Reports and look for the report for your crash (should start with Python_). Under queue, if it shows you "0 libmysqlclient.18.dylib", then you have the same problem as I had.
As already mentioned you do not need DATABASE_PATH.
My working configuration looks like:
DATABASES = {
'default': {
'ENGINE': 'mysql.connector.django',
'NAME': 'db_name',
'USER': 'db_user',
'PASSWORD': 'db_pass',
'HOST': '127.0.0.1',
}
}
I am using a different engine, because it is required for Python3. → see documentation
After that you have to create the database and the user. Do not forget to give all needed rights to the user.
With python manage.py migrate your database is populated with your models.
syncdb the predecessor to migrate will be removed in Django 1.9

Categories

Resources