sqlalchemy.exc.OperationalError: (pymysql.err.OperationalError) (1059, "Identifier name is too long") - flask

I got this error when I tried to inspect db that I created before.
And I used this below command to make existing table as models.py file.
flask-sqlacodegen "mysql+pymysql://[DBUser]:[DBPassword]#[DBhost]:3306/[TableName]" > models.py
Is there any idea about this problem?
And how to make models.py file with already existing database in flask?
Please give me any suggestions to solve this problem.

Related

How can I add atribute to webpage in django

screenshotI'm following a tutorial to create a website using django. I keep getting this error when running the server.
path('page2',index.webpage2),
AttributeError: module 'website.index' has no attribute 'webpage2'. Did you mean: 'webpage1'?
Don't know what I'm missing, the tutorial ran the server without any problem. The only thing I noticed was that it also gave my a missing os error. I fixed this part.
Thank you for your help
You need to add two views correspoending to the url
def webpage2(request):
pass
def webpage3(request):
pass

How to get Django Report Builder working properly?

Documentation provided by Burke isn't very thorough and there isn't a lot of information on Django Report Builder yet, not even youtube videos. Does anybody have any information on how to get work Report Builder Working in Django? I currently keep getting this error message:
(1146, "Table 'epic_test2.report_builder_report' doesn't exist")
I've installed it, but I can't create reports yet and the documentation I do have isn't very helpful. Any advice would be great! Thanks!
UPDATE TO POST/ 5.12.15 -
I fixed the first issue, but now I have a new error. :) Yay. It's a Field Error
"Cannot Resolve keyword 'name' into field. Choices are: app_label, id, logentry, model, permission, report.
ANY clues for this one would be helpful... going into third hour of troubleshooting. :)
Thanks!
~Heather
Sounds like you may need to run a migrate to create the Report Builder tables required.
python manage.py migrate
I would suggest you do a full search in your code for "name", something like: grep -R "name" ., and see where it's defined, is it a valid field in models.py, etc.
I've had similar error before, turned out, I updated my variable name from something like "name" to "new_name" in my model. The way report-builder works, it saves column (field) name in the database. If it's an old field name, there will be error. Luckily this is easy to fix: go to report-builder UI, remove the row for that column, then add the column back, then the new field name would be saved.
Hope this helps.

Any ideas why my fixture won't load for Django test?

This is the first time I've tried loading a fixture for my unit tests in Django, and I have no idea why it won't load. I dumped the data from my app with dumpdata command and that works fine. When I loaddata from command line or run my tests with fixtures set at my data file I get the following error:
DeserializationError: Problem installing fixture 'data.json': [u"'' value must be an integer."]
Tried with xml format:
ValidationError: [u"'' value must be an integer."]
It seems like Django is looking for an IntergerField, but it is blank? Anybody have any idea what is going on here or any way to get a more verbose error message that would maybe tell me what model it is on?
After dumping each individual model to determine which one caused the error, I found a field that was blank. I don't understand why it didn't work being the field was set to blank=True, null=True. Feel free to let me know.

"Error: near "Documents": syntax Error" - sqlite3/Django

I am trying Chapter 6 from Django book.
After changing some fields to blank=True, and null=True, we are told to update the table using dbshell.
When I type: python manage.py dbshell, the following error appears:
C:\Users\Rafa\Documents\Python\book>python manage.py dbshell
Error: near: "Documents": syntax error.
I tried installing sqlite3.exe in my book directory and running directly from there. I still get the same error anytime I try to run a command. For example, once on the sqlite3 shell (opening executable file):
sqlite>ALTER TABLE books_book ALTER COLUMN publication_date DROP NOT NULL;
Error: near "ALTER": syntax error.
I know the commands may be wrong, but I can try anything and it will always point the same error and show the first word of the command in the "".
Any help?
SQLite has very limited ALTER TABLE support.
You have to drop and recreate the table.
As the error message suggests, there is a syntax error somewhere. You should check (or post here) the parts which describe Documents class for some syntactic mistakes :)
I realize now that Django does not support database migrations very well. Once you do the initial migration and the original table is set, it is impossible to add or modify fields with Django only. You need a database migration schema like South.

Error With South When Running Unit Tests Using Nose

I'm having some difficulty getting my django tests to run properly; I'm using nose, and I started getting an error when the migrations were being applied, that from table 1 a foreign key relation to table 2 failed with the error:
django.db.utils.DatabaseError: relation "table2_column" does not exist
Looking at the way the migrations were being applied it was clear to me that table1 was not created prior to the foreign key relation was applied, so I tried to figure out how to force the dependency, and found the following article:
http://south.aeracode.org/docs/dependencies.html
I then added:
depends_on = (
("app2", "0001_inital"),
)
to my app1/0001_initial.py file.
Unfortunately now I'm getting the following error:
south.exceptions.DependsOnUnknownMigrationMigration 'app1:0001_initial' depends on unknown migration 'app2:0001_inital'.
Any ideas on how to solve this?
I'm not sure if this will solve your problem, but you can add a setting to use syncdb instead of migrations when running tests. Add the following line to your settings.py
SOUTH_TESTS_MIGRATE = False
You have a typo in the name of the migration it's depending on. It should be:
depends_on = (
("app2", "0001_initial"),
)
This dependency system worked for me, after having exactly the same issue you list here, and then finding the dependency system South's docs.
This error is also thrown if there is an error during the import of the target module: If you've got hand-constructed migrations and you're certain the file name matches your depends_on or needed_by, check the referenced file for errors.
Also, setting SOUTH_TESTS_MIGRATE to False won't fix the problem. It just means you won't see the problem until you try to use the migration.
http://south.readthedocs.org/en/latest/settings.html
(That's still useful if you want to speed up your unittests.)