Import sql file to MySQL in pythonanywhere - mysql

I have a django rest app. It works fine with sqlite. Then I switched to using mysql. After I migrated the project. I imported a sql file to MySQL database. but got an error:
Table 'myusername$databasename.table_name1' doesn't exist
Table 'myusername$databasename.table_name2' doesn't exist
...
I don't understand. This sql file was exported from the same django project.
Please help me.

It seems you will need to create those tables first. That would correspond to the django command
./manage.py migrate

Related

migrate in django to legacy database gives error

Background info:
I am quite beginner with django, better equipped with python and quite beginner in mysql (and thus mariaDB) as well.
I work in Windows 7 environment with the following versions:
django 1.9.1
mariaDB 10.0.20
Python 3.4.4
mysql-connector\Python 2.1.3 for Python 3.4
Goal:
I am trying to build mariaDB database and web based user interface for it with django. I have built the database beforehand in mysql and am now trying to create the django project using this database as legacy database.
Problem:
I have retrieved the models to my django project as follows:
python manage.py inspectdb > models.py
and it worked fine. Checked the models.py, as well, and they seemed as they should.
Now, if I try to migrate to create the tables based on django to my legacy db as follows:
python manage.py migrate
I keep getting plenty of nested errors last one being:
django.db.migrations.exceptions.MigrationsSchemaMissing: Unable to create the django_migrations table (Table 'mydb'.'django_migrations' already exists. Please DISCARD the tablespace before IMPORT.)
I figured the table was left in my database folder from previous attempt, but removing it does not help. Even if I check from the database command prompt that the only tables left are native to my database, this same error message pops up still. At some point I wondered if there is some issue with the connector I am using as it is not the recommended one (mysqlclient).
Somewhere, I found that the migration would not even be required. This would obviously save me, but I have no idea, if that is a solution I can go for. Ideally the database would be managed later online and users with admin accounts could add entries there. Otherwise, however the database should be just returning the data.
EDIT: Fixed the error message the python manage.py inspectdb > models.py line
EDIT 29.1.
Running the migration as:
python manage.py migrate --fake
results in the same error.
The issue persists even after removing the django project and starting it fresh.
EDIT v2 29.1.
There is only one of the required table files for the django_migrations table within the database folder. There should be django_migrations.ibd AND django_migrations.frm. However, after running the migration, there is only one file: django_migrations.ibd.
There was something similar going on here, with different file
mysqldump problems with restore error: 'Please DISCARD the tablespace before IMPORT'. It is well explained in the chosen answer.
I think this is related to my issue, but cannot figure out what could help and what to do with this.
EDIT v3 29.1.
And finally I noticed the file giving the django error. It is django's migration recorder at C:\Python34\lib\site-packages\django\db\migrations\recorder.py on line 59.
def ensure_schema(self):
"""
Ensures the table exists and has the correct schema.
"""
# If the table's there, that's fine - we've never changed its schema
# in the codebase.
if self.Migration._meta.db_table in self.connection.introspection.table_names(self.connection.cursor()):
return
# Make the table
try:
with self.connection.schema_editor() as editor:
editor.create_model(self.Migration)
except DatabaseError as exc:
raise MigrationSchemaMissing("Unable to create the django_migrations table (%s)" % exc)
Where the last line raising the error is the line 59. Funnily, the function should work, if the table exists. Only thing I can come up with (as in my previous edit), is that indeed for some reason the frm-file is not created during the migration process.
Why that happens is way beyond me.

migrating rails app from postgresql to mysql

I'm attempting to migrate my rails application from postgresql to mySQL so as to view the data in one place within xampp in PHPmyadmin. The reason is the fact that I need to access the data that is located within the MySQL database from my rails app which is in postgresql.
As of now most questions I found aim to create a new application within mySQL with rails but I need to migrate all of the data my current rails application compatible and use MySQL.
Is there a proper process and simple procedure that allows for this migration from postgresql to mySQL?
Note: MySQL is within xampp
this post
got the answer to your question.
It's very easy, just paste your postgres dump in this website and you'll get the same dump converted in mysql, ready for you to be imported.
Then you will just need to properly configure your database.yml and you're set.

Importing data using MySQL Administrator

I currently have a massive excel file of which the data i'd like to import it into my already setup MySQL Server and Table
I have MySQL Administrator installed, so I was wondering if MySQL Admin can import excel files to SQL tables or if I should install another program to do what I want?
Thanks.
I found this: http://www.aspfree.com/c/a/Database/Converting-Your-Excel-Worksheet-into-a-Working-MySQL-Database/ and it worked perfectly fine

How can I import a sqlite database created in django?

Iam a beginner to django. I did run syncdb after mentioning the database file in manage.py. Is it possible to view the contents (tables) of the database in mysql or phpmyadmin?
Run dbshell:
python manage.py dbshell
This will put you in a shell as if running mysql with the correct connection params.
If you want to use phpmyadmin with it, that's a matter of correct phpmyadmin configuration, which depends only on your database, it has nothing to do with Django. So check your phpmyadmin settings and configure your database the same way you did in settings.py of the Django project.
phpMyAdmin does not support SQLite databases.

SQLite and MySQL, will the conflict?

I just joined a project where they have been using SQLite. I am more comfortable using MySQL with PHPMyAdmin. If I install phpMyAdmin and work with that will it do any damage?
It is a php project. They have alot of code (sloppy code thats so hard to figure out) for accessing a SQLite db. I dont want to effect that but I want to add some new tables to a new db using mysql and phpmyadmin which i am yet to set up because I'm afraid it will break the code written for the SQLite db
.
Are you talking merely about installing PHPMyAdmin to manage a SQLite database? That won't work, since both use completely different API's to be accessible through PHP.
Or do you wish to swap the SQLite database with MySQL and then use PHPMyAdmin to manage the database? That'll work, as long as the project supports both SQLite and MySQL.
Is it a PHP project? Probably not - mysql_-prefixed methods only work with MySQL as far as I know, and SQLite and MySQL don't listen on the same port by default, do they?
You need to work with what is deployed. If the project is using Sqlite, then use that. Databases are not all equal. If you use something different, your code might not even run on the production databases.
first of all, if you don't want affect, create a branch on github then from work this branch ..
you can also dump all table of this sqlite database to a sql file, then import this file to your phpAdmin, will create the table, since this both manager uses sql language ... just remove some ligne of code that are not compatible with mysql on sql file that you dump data from sqlite dabtase .....
here is the code for dump a sqlite database ....
first select the database on terminal on your project director
sqlite3
./open DATABASENAME
.output YOURSQLFILENAME.sql
.dump
.quit
at this stage you already have your database in a sql file
then use php admin to import this file
if it show some error, just try to remove somecode that aren't compatible with mysql on sqlfile.