I have a database with around 25 tables and I would like to automatically generate the model file for my python project. For developing the project I am using PyCharm with a MariaDB as RDMS.
The basic settings for the database have been done. In the next step I switch to the manage.py console to run the first command:
inspectdb
This is working fine. Each table will be listed in the output of the console window. Now I want to write the output in a file. Therefore I use the following command:
inspectdb > models.py
This ends up in an Error:
Unable to inspect table '>'
# The error was: (1146, "Table 'mydatabase.>' doesn't exist")
# Unable to inspect table 'models.py'
# The error was: (1146, "Table 'mydatabase.models.py' doesn't exist")
Process finished with exit code 0
The command is according to the documentation 'python manage.py inspectdb > model.py'. But in this case the '>' symbol will be intepreted as table, or a tablename has to be given.
In a second case, I try to export only one table:
inspectdb users > models.py
this ends up with the following output:
class Users(models.Model):
name = models.CharField(max_length=400)
username = models.CharField(max_length=150)
email = models.CharField(max_length=100)
password = models.CharField(max_length=100)
.....
class Meta:
managed = False
db_table = 'users'
# Unable to inspect table '>'
# The error was: (1146, "Table 'mydatabase.>' doesn't exist")
# Unable to inspect table 'models.py'
# The error was: (1146, "Table 'mydatabase.models.py' doesn't exist")
Process finished with exit code 0
Same problem here! In this case the model users is generated, but it is not written to the models.py file. What do I have to do, to save the generated models into my models.py file?