Postgresql: migrating local database to the PythonAnywhere database - python

I've followed the Djangogirls tutorial and usually the tutorial calls for you to create a database on pythonanywhere. This usually works without a hitch when using sqlite3 however this time I'm using postgresql and I got the below error when I ran the migrate command in the console:
conn = _connect(dsn, connection_factory=connection_factory, async=async)
django.db.utils.OperationalError: could not connect to server: No such file or directory
Is the server running locally and accepting
connections on Unix domain socket "/var/run/postgresql
What does this mean exactly?
using python 3.5.1
django 1.9.8
postgresql 9.4
Thanks
Ok after reading around some more, this is my problem in a nutshell.
I have postgresql running locally. I then deployed the wbapp onto pythonanywhere. Whilst there I tried to create the database by running migrate which resulted in the above error.
Since then i realised that I had to setup postgresql to run on pythonanywhere. I followed the instructions and did that, but what I don't understand is do I now have to create the database from scratch? And if that is the case what happens to all my tables etc. from my local database?

To clarify, you should not be trying to connect to your local postgres. Instead, you should setup postgres on pythonanywhere, and make sure that your django settings.py is pointing the database address and port to the pythonanywhere database. Which is not local to the console/webapp server that you are running your code on. Instead, go to the pythonanywhere database tab and look at the address/port that is given to you.

According to their help page you need to upgrade to a paid account to be able to use postgres.

Related

is mysql connector module can run in another pc

first of all, sorry for this dumb question.
secondly, this is the scenario, i made executable file from python, my app need to connect to mysql database, in my app script is using mysql.connector.
thirdly, what i want to know, is my app can run and connect to mysql database in another pc that does not have mysql driver installed? *because of poor resource, right now i can't just try and find out my self.
if it can't, can i using sqlite and then all the pc client data saved in 1 file database that place in shared folder, so 'admin' can read it anytime?
thank you so much

Find Server name on postgresql?

I have made a PostgreSQL database, and I am trying to connect a python script to it. I need to enter the server name to the script. I have the database name, but I don't know what the server name is. Where do I find that? If it helps I am working through Heroku Postgres.
The official article in the DevCenter states:
To use PostgreSQL as your database in Python applications you will need to use the psycopg2 [...] to connect to DATABASE_URL in your code.
So I guess there is no server name needed with that package.

An app deployed to Heroku can't access to MySQL database in cPanel remotely

i am deploying a python app to Heroku, an there is an error when accessing the app after deployment,
(pymysql.err.OperationalError) (2003, "Can't connect to MySQL server
obviously it is about my login system which is using MySQL to store the usernames and passwords.
Now this database sits in my cPanel, and i have already set the Remote MySQL Access hosts to a wild card "%" (trying to allow all incoming request from all ips to this database).
But now it seems this app on Heroku can't access to this database. Any solution for that?
Any help is appreciated.
if it helps create a php database query api script on your server that hosts the database and access it from your python code on heroku with requests package.

How can I switch my Django project's database engine from Sqlite to MySQL?

I need help switching my database engine from sqlite to mysql. manage.py datadump is returning the same error that pops up when I try to do anything else with manage.py : ImproperlyConfigured: Error loading MySQL module, No module named MySQLdb.
This django project is a team project. I pulled new changes from bitbucket and our backend has a new configuration. This new configuration needs mysql (and not sqlite) to work. Our lead dev is sleeping right now. I need help so I can get started working again.
Edit: How will I get the data in the sqlite database file into the new MySQL Database?
According to the Database setup paragraph in Django docs:
By default, the configuration uses SQLite.
If you wish to use another database, install the appropriate database
bindings...
And Get your database running page says:
If you’re using MySQL, you’ll need the MySQL-python package, version
1.2.1p2 or higher.
To use MySQL backend you need a tool that would help Django talk to the database, an adapter.
In other words, MySQL-python (aka MySQLdb) package needs to be installed.
Try the followings steps:
1. Change DATABASES in settings.py to MYSQL engine
2. Run $ ./manage.py syncdb

When I run Django on Dreamhost using SQLite, why do I get an OperationalError telling me that a table doesn’t exist?

I had a Django site running on Dreamhost. Although I used SQLite when developing locally, I initially used MySQL on Dreamhost, because that’s what the wiki page said to do, and because if I’m using an ORM, I might as well take advantage of it by running against a different database.
After a while, I switched the settings on the server to use SQLite, to make it easier to keep my development database in sync with the server one. python manage.py syncdb worked on the server, but when I tried to access the site, I got an OperationalError. The Django error page said that one of my tables didn’t exist.
I checked the database using sqlite on the command line on the server, and using python manage.py shell, and both worked fine.
It turned out that on the server, the DATABASE_NAME setting required a full path, e.g.
DATABASE_NAME = '/home/USERNAME/SITE/DJANGOPROJECT/DATABASE.db'
Locally (and I guess for manage.py on the server), just a filename was fine, e.g.
DATABASE_NAME = 'DATABASE.db'

Categories